nix-da/modules/scripts/default.nix
nydragon f756c287a9
Some checks are pending
/ test (push) Waiting to run
feat: add hyprland grouping keybinds
2025-03-20 20:46:10 +01:00

150 lines
3.9 KiB
Nix

{
pkgs,
lib,
config,
...
}:
let
inherit (pkgs.writers) writeFishBin writeBashBin;
inherit (lib.my) getExe;
runner = config.modules.system.roles.desktop.runner;
nixos-rebuild =
name: word:
writeFishBin name ''
env --chdir ~/.nixconf ${pkgs.nh}/bin/nh os ${word} . $argv \
&& ${lib.my.getExe' pkgs.libnotify "notify-send"} nixos-rebuild "Rebuild complete" \
-a nixos-rebuild \
-i ${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg
'';
in
{
screenshot = pkgs.writeShellApplication {
name = "screenshot";
runtimeInputs = with pkgs; [
wl-clipboard
libnotify
hyprshot
xdg-utils
];
text = ''
set -e
location="$XDG_PICTURES_DIR/screenshots/$(date +%Y-%m-%d-%H%M%S)-screenshot.png";
hyprshot -r -z -m region | tee "$location" | wl-copy --type image/png;
body="<img src=\"$location\"\>"
response=$(
notify-send \
"Copied to clipboard" \
"$body" \
--app-name Screenshot \
-i "$location" \
--urgency=low \
--action=COPY=Copy \
--action=OPEN=Open \
--action=DELETE=Delete
)
case "$response" in
"DELETE")
rm "$location"
;;
"COPY")
wl-copy <"$location"
;;
"OPEN")
xdg-open "$location"
;;
esac
'';
};
set-background = writeFishBin "set-background" ''
argparse 'f/file=!test -e "$_flag_value"' -- $argv; or return
set pids $(pidof swaybg)
if set -q _flag_file
${pkgs.swaybg}/bin/swaybg -i "$(find $_flag_file | shuf -n 1)" > /dev/null 2>&1 &
else
${pkgs.swaybg}/bin/swaybg -i "$(find ~/Pictures/backgrounds | shuf -n 1)" > /dev/null 2>&1 &
end
sleep 0.5;
for i in $(string split " " $pids)
echo "killing process $i";
kill -9 "$i";
end
'';
nixedit = writeFishBin "nixedit" "env --chdir ~/.nixconf $EDITOR .";
getext = pkgs.writeScriptBin "getext" "ls | grep -E \"\.[a-zA-Z0-9]+$\" --only-matching | sort | uniq";
rpaste = writeFishBin "rpaste" ''
${getExe pkgs.rustypaste-cli} -a "$(cat ${config.age.secrets.rustypaste.path})" -s "https://rusty.ccnlc.eu/" $argv
'';
gentest = nixos-rebuild "gentest" "test";
genswitch = nixos-rebuild "genswitch" "switch";
fishl = writeFishBin "fishl" ./logo.fish;
nrun = writeFishBin "nrun" ''
if echo "$argv[1]" | grep -Eq '^[a-z]+:.+/.+$'
nix run $argv[1] -- $argv[2..]
else
nix run nixpkgs#$argv[1] -- $argv[2..]
end
'';
nruni = writeFishBin "nruni" ''
export NIXPKGS_ALLOW_UNFREE=1;
export NIXPKGS_ALLOW_INSECURE=1
if echo "$argv[1]" | grep -Eq '^[a-z]+:.+/.+$'
nix run --impure $argv[1] -- $argv[2..]
else
nix run --impure nixpkgs#$argv[1] -- $argv[2..]
end
'';
editsym = writeFishBin "editsym" ''
for file in $argv
cp "$file" "$file.tmp"
unlink "$file"
mv "$file.tmp" "$file"
chmod -R 777 "$file"
end
'';
deploytest = writeFishBin "deploytest" ''
nixos-rebuild test \
--flake ~/.nixconf#"$argv[1]" \
--target-host "$argv[1]" \
--use-remote-sudo &| ${getExe pkgs.nix-output-monitor}
'';
deployswitch = writeFishBin "deployswitch" ''
nixos-rebuild switch \
--flake ~/.nixconf#"$argv[1]" \
--target-host "$argv[1]" \
--use-remote-sudo &| ${getExe pkgs.nix-output-monitor}
'';
powerMenu = writeBashBin "power-menu" ''
case "$(echo -e "Shutdown\nRestart\nHibernate\nLogout\nSuspend\nLock" | ${runner.dmenu} )" in
Shutdown) exec systemctl poweroff ;;
Restart) exec systemctl reboot ;;
Logout) exec loginctl terminate-session "$${XDG_SESSION_ID-}" ;;
Hibernate) exec systemctl hibernate ;;
Suspend) exec systemctl suspend ;;
Lock) exec loginctl lock-session "$${XDG_SESSION_ID-}" ;;
esac
'';
}