web bookmarks

This commit is contained in:
vrd
2026-07-30 11:54:49 +03:00
committed by Venelin Dechkov
parent 491e29fefa
commit 5b8797bccd
4 changed files with 53 additions and 25 deletions
+46 -21
View File
@@ -4,6 +4,7 @@
#include <fstream>
#include <string>
#include <chrono>
#include <filesystem>
#include <cppipe/commands.hpp>
// #include "vene.h"
#include "vene_env.h"
@@ -11,6 +12,7 @@
using namespace std;
using namespace std::chrono;
using namespace std::chrono_literals;
namespace fs = std::filesystem;
char* HOME;
char SCREEN_CAPS_DIR[64];
@@ -20,6 +22,7 @@ namespace
time_point<system_clock> next_update;
bool has_child;
Proc child;
Proc browser = {.pid = 0};
}
extern "C"
@@ -32,6 +35,7 @@ extern "C"
const void *v;
} Arg;
void updatestatus();
void view(const Arg* arg);
// end
void vene_setup()
@@ -111,38 +115,59 @@ extern "C"
}
else if(now > next_update)
{
// Clean up all zombies
while (waitpid(-1, nullptr, WNOHANG) > 0);
updatestatus();
next_update = now + 10s;
}
}
void vene_webbookmark()
void vene_browser(const Arg* arg)
{
using std::string;
Cmd dmenu( "dmenu", "-f", "-b", "-l", "30");
if( browser.pid == 0 || check_exited(browser) ) // not running
{
browser = Cmd(BROWSER).detach();
string bookmark (HOME);
bookmark += "/sync/bookmarks/web/";
// Clean up all zombies
while (waitpid(-1, nullptr, WNOHANG) > 0);
}
else // running, view it
{
view(arg);
}
}
void vene_webbookmark() // todo: cppipe exceptions
{
Cmd dmenu( "dmenu", "-b", "-f", "-i", "-l", "30");
string bm_root (HOME);
bm_root += "/sync/bookmarks/web/";
Cmd list_dirs ("ls");
list_dirs += bookmark.c_str();
list_dirs += bm_root.c_str();
// Choose bookmark directory
bookmark += $(list_dirs | dmenu);
bookmark.pop_back(); // remove trailing newline
// Choose bookmark
string link =$(dmenu < bookmark.c_str());
size_t link_begin = link.find('-') + 1;
if(link_begin != string::npos)
while(true)
{
Cmd open_bookmark(BROWSER);
link = link.substr(link_begin);
open_bookmark += link.c_str();
open_bookmark.detach();
// Choose bookmark directory
string dir = $(list_dirs | dmenu);
if( dir.empty() )
return;
string bm_dir = bm_root;
bm_dir += dir;
bm_dir.pop_back(); // remove trailing newline
// Choose bookmark
string link = $(dmenu < bm_dir.c_str());
size_t link_begin = link.find('-');
if(link_begin != string::npos)
{
Cmd open_bookmark(BROWSER);
link = link.substr(link_begin+1);
open_bookmark += link.c_str();
open_bookmark.detach();
break;
}
}
}