Add bookmark this script

Based on Luke Smith's script created during his "Bookmarking for Unix
Chads (For Browsers, Terminals, IDEs and everything else)" video.

https://videos.lukesmith.xyz/w/o5fiME4oJMdVzwSu7mA9mc
This commit is contained in:
Oliver Davies 2025-05-06 23:18:14 +01:00
parent 9215133b9f
commit b2ff96aa9e
5 changed files with 77 additions and 2 deletions
home/opdavies
modules/home-manager/cli
overlays/mods/dwm

View file

@ -4,6 +4,7 @@
imports = [ ../common ];
cli = {
bookmarkthis.enable = true;
direnv.enable = true;
fzf.enable = true;

View file

@ -5,6 +5,7 @@
cli = {
bluetuith.enable = true;
bookmarkthis.enable = true;
direnv.enable = true;
fzf.enable = true;

View file

@ -0,0 +1,68 @@
{
config,
lib,
pkgs,
...
}:
let
inherit (lib) mkEnableOption mkOption;
cfg = config.cli.${name};
name = "bookmarkthis";
in
{
options.cli.${name} = {
enable = mkEnableOption "Enable ${name}";
snippetsFile = mkOption {
default = "${config.xdg.dataHome}/snippets.txt";
type = lib.types.str;
};
};
config = lib.mkIf cfg.enable {
home = {
packages = with pkgs; [
(pkgs.writeShellApplication {
name = "bookmarkthis";
text = ''
message() {
if command -v ${lib.getExe libnotify} > /dev/null; then
${lib.getExe libnotify} "$1" "$2"
else
echo "$2"
fi
}
main() {
bookmark="$(xclip -o)"
file="$SNIPPETS_FILE"
if grep -q "^$bookmark$" "$file"; then
message "Oops." "Already bookmarked." >&2
exit 2
fi
echo "$bookmark" >> "$file"
message "Bookmark added!" "$bookmark is now saved to the file."
}
main
'';
})
];
sessionVariables = {
SNIPPETS_FILE = cfg.snippetsFile;
};
};
programs.zsh.zsh-abbr.abbreviations = lib.optionalAttrs (config.programs.zsh.enable) {
"sn" = "${config.home.sessionVariables.EDITOR} $SNIPPETS_FILE";
};
};
}

View file

@ -1,6 +1,7 @@
{
imports = [
./bluetuith.nix
./bookmarkthis.nix
./dev-commit.nix
./direnv.nix
./fzf.nix

View file

@ -5,6 +5,9 @@ let
in
prev.dwm.override {
conf = ''
#define BROWSER "${lib.getExe prev.librewolf}"
#define TERMINAL "${lib.getExe prev.st}"
static const unsigned int borderpx = 1;
static const unsigned int snap = 32;
static const int showbar = 1;
@ -51,7 +54,7 @@ prev.dwm.override {
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL };
static const char *termcmd[] = { TERMINAL, NULL };
static const Key keys[] = {
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
@ -86,13 +89,14 @@ prev.dwm.override {
TAGKEYS(XK_7, 6)
TAGKEYS(XK_8, 7)
TAGKEYS(XK_9, 8)
{ MODKEY|ShiftMask, XK_b, spawn, SHCMD("${lib.getExe prev.librewolf}") },
{ MODKEY|ShiftMask, XK_b, spawn, {.v = (const char*[]){ "/etc/profiles/per-user/opdavies/bin/bookmarkthis", NULL }}},
{ MODKEY|ShiftMask, XK_f, spawn, SHCMD("${prev.xfce.thunar}/bin/thunar") },
{ MODKEY|ShiftMask, XK_i, spawn, SHCMD("${prev.xdotool}/bin/xdotool type $(cat ~/.local/share/snippets.txt | grep -v '^#' | grep -v '^$' | sort | dmenu -i -l 50 | cut -d' ' -f1)") },
{ MODKEY|ShiftMask, XK_p, spawn, {.v = (const char*[]){ "${lib.getExe prev.passmenu-otp}", "-i", NULL} } },
{ MODKEY|ShiftMask, XK_q, quit, {0} },
{ MODKEY|ShiftMask, XK_r, quit, {1} },
{ MODKEY|ShiftMask, XK_s, spawn, SHCMD("${prev.flameshot}/bin/flameshot gui") },
{ MODKEY, XK_w, spawn, SHCMD(BROWSER) },
{ MODKEY, XK_F3, spawn, {.v = (const char*[]){ "${lib.getExe prev.displayselect}", NULL} } },
{ MODKEY, XK_F9, spawn, {.v = (const char*[]){ "/home/opdavies/.local/bin/mounter", NULL } } },
{ MODKEY, XK_F10, spawn, {.v = (const char*[]){ "/home/opdavies/.local/bin/unmounter", NULL } } },