Add bookmark this script
All checks were successful
/ check (push) Successful in 1m12s

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

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