refactor: expose all scripts as modules

This commit is contained in:
Swarsel 2024-07-29 17:01:19 +02:00
parent db231d4b83
commit 8f4fe686a5
Signed by: swarsel
GPG key ID: 26A54C31F2A4FD84
29 changed files with 785 additions and 330 deletions

7
pkgs/check/default.nix Normal file
View file

@ -0,0 +1,7 @@
{ writeShellApplication, kitty, element-desktop-wayland, discord, spotify-player, sway, jq }:
writeShellApplication {
name = "swarselcheck";
runtimeInputs = [ jq ];
text = builtins.readFile ../../scripts/check.sh;
}

40
pkgs/cnf/default.nix Normal file
View file

@ -0,0 +1,40 @@
{ writeShellApplication, ncurses, nix-index }:
writeShellApplication {
name = "cnf";
runtimeInputs = [ ncurses nix-index ];
text = ''
command_not_found_handle () {
if [ -n "''${MC_SID-}" ] || ! [ -t 1 ]; then
>&2 echo "$1: command not found"
return 127
fi
echo -n "searching nix-index..."
ATTRS=$(nix-locate --minimal --no-group --type x --type s --top-level --whole-name --at-root "/bin/$1")
case $(echo -n "$ATTRS" | grep -c "^") in
0)
>&2 echo -ne "$(tput el1)\r"
>&2 echo "$1: command not found"
;;
*)
>&2 echo -ne "$(tput el1)\r"
>&2 echo "The program $(tput setaf 4)$1$(tput sgr0) is currently not installed."
>&2 echo "It is provided by the following derivation(s):"
while read -r ATTR; do
ATTR=''${ATTR%.out} # Strip trailing '.out'
>&2 echo " $(tput setaf 12)nixpkgs#$(tput setaf 4)$ATTR$(tput sgr0)"
done <<< "$ATTRS"
esac
return 127
}
command_not_found_handler () {
command_not_found_handle "$@"
return $?
}
'';
}

View file

@ -4,10 +4,13 @@ let
in
{
pass-fuzzel = callPackage ./pass-fuzzel { };
pass-fuzzel-otp = callPackage ./pass-fuzzel-otp { };
cura5 = callPackage ./cura5 { };
cdw = callPackage ./cdw { };
cdb = callPackage ./cdb { };
bak = callPackage ./bak { };
timer = callPackage ./timer { };
e = callPackage ./e { };
swarselcheck = callPackage ./swarselcheck { };
waybarupdate = callPackage ./waybarupdate { };
opacitytoggle = callPackage ./opacitytoggle { };
}

7
pkgs/e/default.nix Normal file
View file

@ -0,0 +1,7 @@
{ writeShellApplication, emacs-pgtk, sway, jq }:
writeShellApplication {
name = "e";
runtimeInputs = [ emacs-pgtk sway jq ];
text = builtins.readFile ../../scripts/e.sh;
}

7
pkgs/ew/default.nix Normal file
View file

@ -0,0 +1,7 @@
{ writeShellApplication, emacs-pgtk, sway, jq }:
writeShellApplication {
name = "ew";
runtimeInputs = [ emacs-pgtk sway jq ];
text = builtins.readFile ../../scripts/editor-wait.sh;
}

View file

@ -0,0 +1,7 @@
{ writeShellApplication, sway }:
writeShellApplication {
name = "opacitytoggle";
runtimeInputs = [ sway ];
text = builtins.readFile ../../scripts/opacitytoggle.sh;
}

View file

@ -3,30 +3,5 @@
writeShellApplication {
name = "pass-fuzzel-otp";
runtimeInputs = [ fuzzel (pass.withExtensions (exts: [ exts.pass-otp ])) ];
text = ''
shopt -s nullglob globstar
typeit=0
if [[ $# -ge 1 && $1 == "--type" ]]; then
typeit=1
shift
fi
export PASSWORD_STORE_DIR=~/.local/share/password-store
prefix=''${PASSWORD_STORE_DIR-~/.local/share/password-store}
password_files=( "$prefix"/otp/**/*.gpg )
password_files=( "''${password_files[@]#"$prefix"/}" )
password_files=( "''${password_files[@]%.gpg}" )
password=$(printf '%s\n' "''${password_files[@]}" | fuzzel --dmenu "$@")
[[ -n $password ]] || exit
if [[ $typeit -eq 0 ]]; then
pass otp -c "$password" &>/tmp/pass-fuzzel
else
pass otp "$password" | { IFS= read -r pass; printf %s "$pass"; } | wtype -
fi
notify-send -u critical -a pass -t 1000 "Copied/Typed OTPassword"
'';
text = builtins.readFile ../../scripts/pass-fuzzel-otp.sh;
}

View file

@ -2,31 +2,6 @@
writeShellApplication {
name = "pass-fuzzel";
runtimeInputs = [ libnotify pass fuzzel wtype ];
text = ''
shopt -s nullglob globstar
typeit=0
if [[ $# -ge 1 && $1 == "--type" ]]; then
typeit=1
shift
fi
export PASSWORD_STORE_DIR=~/.local/share/password-store
prefix=''${PASSWORD_STORE_DIR-~/.local/share/password-store}
password_files=( "$prefix"/**/*.gpg )
password_files=( "''${password_files[@]#"$prefix"/}" )
password_files=( "''${password_files[@]%.gpg}" )
password=$(printf '%s\n' "''${password_files[@]}" | fuzzel --dmenu "$@")
[[ -n $password ]] || exit
if [[ $typeit -eq 0 ]]; then
pass show -c "$password" &>/tmp/pass-fuzzel
else
pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | wtype -
fi
notify-send -u critical -a pass -t 1000 "Copied/Typed Password"
'';
runtimeInputs = [ libnotify (pass.withExtensions (exts: [ exts.pass-otp ])) fuzzel wtype ];
text = builtins.readFile ../../scripts/pass-fuzzel.sh;
}

View file

@ -0,0 +1,7 @@
{ writeShellApplication, kitty, element-desktop-wayland, discord, spotify-player, sway, jq }:
writeShellApplication {
name = "swarselcheck";
runtimeInputs = [ kitty element-desktop-wayland discord spotify-player jq ];
text = builtins.readFile ../../scripts/swarselcheck.sh;
}

View file

@ -0,0 +1,7 @@
{ writeShellApplication, git }:
writeShellApplication {
name = "waybarupdate";
runtimeInputs = [ git ];
text = builtins.readFile ../../scripts/waybarupdate.sh;
}