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:
parent
9215133b9f
commit
b2ff96aa9e
5 changed files with 77 additions and 2 deletions
68
modules/home-manager/cli/bookmarkthis.nix
Normal file
68
modules/home-manager/cli/bookmarkthis.nix
Normal 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";
|
||||
};
|
||||
};
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
imports = [
|
||||
./bluetuith.nix
|
||||
./bookmarkthis.nix
|
||||
./dev-commit.nix
|
||||
./direnv.nix
|
||||
./fzf.nix
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue