From 4c469658f9a5d7b169a0267ef1849da7e42f2c87 Mon Sep 17 00:00:00 2001 From: Rosa Date: Sat, 2 May 2026 18:14:47 -0400 Subject: move screenshot script to separate file --- .gitignore | 1 + flake.nix | 4 ++++ modules/user/desktop/apps/fuzzel.nix | 1 + modules/user/desktop/scripts/screenshot.sh | 16 ++++++++++++++++ modules/user/desktop/sessions/sway.nix | 21 +++++++-------------- 5 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 modules/user/desktop/scripts/screenshot.sh diff --git a/.gitignore b/.gitignore index 329f92f..f71976b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.direnv +/.envrc *.key diff --git a/flake.nix b/flake.nix index 5f9a821..0303b9d 100644 --- a/flake.nix +++ b/flake.nix @@ -44,6 +44,10 @@ }; in { + devShells.x86_64-linux.default = pkgs.mkShellNoCC { + nativeBuildInputs = with pkgs; [ shellcheck ]; + }; + formatter.x86_64-linux = pkgs.nixfmt; nixosConfigurations = { the-meowchine = mkSystem { diff --git a/modules/user/desktop/apps/fuzzel.nix b/modules/user/desktop/apps/fuzzel.nix index 4399237..4d0bdf3 100644 --- a/modules/user/desktop/apps/fuzzel.nix +++ b/modules/user/desktop/apps/fuzzel.nix @@ -12,6 +12,7 @@ counter = "7f849cff"; input = "cdd6f4ff"; match = "cba6f7ff"; + message = "a6adc8ff"; placeholder = "7f849cff"; prompt = "bac2deff"; selection = "585b70ff"; diff --git a/modules/user/desktop/scripts/screenshot.sh b/modules/user/desktop/scripts/screenshot.sh new file mode 100644 index 0000000..f7d607b --- /dev/null +++ b/modules/user/desktop/scripts/screenshot.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# Bash screenshot script. Requires grim, slurp, sway, fuzzel, libnotify and jq. +IFS=$'\n' +screenshot_targets=$(swaymsg -rt get_outputs | jq -r '.[].name' | sort) +screenshot_targets+=($'\nSpecific region') # i LOVE bash +selected_target="$(printf '%s' "${screenshot_targets[@]}" | fuzzel --hide-prompt --mesg='What would you like to screenshot?' --mesg-mode=expand --minimal-lines --dmenu)" +outfile="$HOME/Pictures/Screenshots/$(date +'%F_%H.%M.%S.png')" + +send_notification() { + notify-send "Screenshot taken" "Screenshot saved to $1." +} + +case $selected_target in + 'Specific region') grim -g "$(slurp)" "$outfile" && send_notification "$outfile";; + *) grim -o "$selected_target" "$outfile" && send_notification "$outfile" ;; +esac diff --git a/modules/user/desktop/sessions/sway.nix b/modules/user/desktop/sessions/sway.nix index 3684853..631235a 100644 --- a/modules/user/desktop/sessions/sway.nix +++ b/modules/user/desktop/sessions/sway.nix @@ -9,7 +9,10 @@ config = { gtk.enable = lib.mkDefault config.desktop.sessions.sway.enable; home.packages = lib.mkIf config.desktop.sessions.sway.enable [ + # needed for various scripts pkgs.grim + pkgs.jq + pkgs.libnotify pkgs.slurp ]; @@ -153,26 +156,16 @@ grim = "${pkgs.grim}/bin/grim"; launcher = "${pkgs.fuzzel}/bin/fuzzel"; mod = config.wayland.windowManager.sway.config.modifier; - screenshotDir = "~/Pictures/Screenshots"; + scripts = { + screenshot = pkgs.writeShellScript "screenshot" (builtins.readFile ../scripts/screenshot.sh); + }; terminal = "${pkgs.foot}/bin/foot"; in { "${mod}+Return" = "exec ${terminal}"; "${mod}+R" = "exec ${launcher}"; "${mod}+B" = "exec ${pkgs.librewolf}/bin/librewolf"; - "${mod}+Shift+S" = "exec ${(pkgs.writeShellScript "screenshot" '' - screenshot_type=$(printf 'monitor\nregion' | ${launcher} --mesg='What would you like to screenshot?' --hide-prompt --dmenu --minimal-lines --width=34) - screenshot_filename=$(date +'%F_%H.%M.%S.png') - - send_notif() { - ${pkgs.libnotify}/bin/notify-send -u low "Screenshot taken" "Screenshot saved as $screenshot_filename" - } - - case $screenshot_type in - 'monitor') ${grim} -o $(${pkgs.sway}/bin/swaymsg -rt get_workspaces | ${pkgs.jq}/bin/jq -r '.[] | select(.focused) | .output') ${screenshotDir}/$screenshot_filename && send_notif ;; - 'region') ${grim} -g "$(${pkgs.slurp}/bin/slurp)" ${screenshotDir}/$screenshot_filename && send_notif ;; - esac - '')}"; + "${mod}+Shift+S" = "exec ${scripts.screenshot}"; "${mod}+Alt+L" = "exec ${pkgs.swaylock}/bin/swaylock"; "${mod}+Alt+K" = "input type:keyboard xkb_switch_layout next"; "${mod}+Alt+Q" = "exit"; -- cgit v1.3.1