This commit is contained in:
parent
7cc7808154
commit
c3fa0ce6ce
5 changed files with 57 additions and 71 deletions
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
features = {
|
features = {
|
||||||
cli = {
|
cli = {
|
||||||
bookmarkthis.enable = true;
|
|
||||||
starship.enable = true;
|
starship.enable = true;
|
||||||
zsh.enable = true;
|
zsh.enable = true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
features = {
|
features = {
|
||||||
cli = {
|
cli = {
|
||||||
bookmarkthis.enable = true;
|
|
||||||
starship.enable = true;
|
starship.enable = true;
|
||||||
zsh.enable = true;
|
zsh.enable = true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
{
|
|
||||||
config,
|
|
||||||
lib,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
|
|
||||||
let
|
|
||||||
inherit (lib) mkEnableOption mkOption;
|
|
||||||
|
|
||||||
cfg = config.features.cli.${name};
|
|
||||||
name = "bookmarkthis";
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options.features.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,5 @@
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./bookmarkthis.nix
|
|
||||||
./dev-commit.nix
|
./dev-commit.nix
|
||||||
./starship.nix
|
./starship.nix
|
||||||
./zsh
|
./zsh
|
||||||
|
|
57
modules2/bookmarkthis.nix
Normal file
57
modules2/bookmarkthis.nix
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
{ lib, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
flake.modules.homeManager.gui =
|
||||||
|
{ config, pkgs, ... }:
|
||||||
|
{
|
||||||
|
options.programs.bookmarkthis.snippetsFile = lib.mkOption {
|
||||||
|
default = "${config.xdg.dataHome}/snippets.txt";
|
||||||
|
type = lib.types.str;
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
home = {
|
||||||
|
packages = [
|
||||||
|
(pkgs.writeShellApplication {
|
||||||
|
name = "bookmarkthis";
|
||||||
|
|
||||||
|
text = ''
|
||||||
|
message() {
|
||||||
|
if command -v ${lib.getExe pkgs.libnotify} > /dev/null; then
|
||||||
|
${lib.getExe pkgs.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 = config.programs.bookmarkthis.snippetsFile;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
programs.zsh.zsh-abbr.abbreviations = lib.optionalAttrs (config.programs.zsh.enable) {
|
||||||
|
"sn" = "${config.home.sessionVariables.EDITOR} $SNIPPETS_FILE";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue