nixos-config/scripts/screenshotsh.nix

51 lines
1.4 KiB
Nix
Raw Normal View History

2022-08-08 20:05:06 -03:00
{ config, pkgs, lib, ... }:
pkgs.writeShellScriptBin "screenshotsh" ''
2022-08-09 09:23:07 -03:00
export XCURSOR_SIZE=40
export XCURSOR_THEME='capitaine-cursors-light' # ${pkgs.capitaine-cursors}
2022-08-08 20:05:06 -03:00
2022-08-09 10:04:11 -03:00
screenshot="${pkgs.grim}/bin/grim"
copy="${pkgs.wl-clipboard}/bin/wl-copy -t image/png"
2022-08-09 09:23:07 -03:00
if which xdg-user-dir >/dev/null 2>&1; then
DESTFOLDER="$(${pkgs.capitaine-cursors}/bin/xdg-user-dir PICTURES)"
else
for i in Images Imagens Pictures Fotos ""; do
DESTFOLDER="$HOME/$i"
test -d "$DESTFOLDER" &&
break
done
fi
2022-08-08 20:05:06 -03:00
2022-08-09 09:23:07 -03:00
DESTFOLDER="$DESTFOLDER/Screenshots"
mkdir -p "$DESTFOLDER"
DESTFILE="$DESTFOLDER/$(date +'%Y-%m-%d-%H%M%S_screenshot.png')"
2022-08-08 20:05:06 -03:00
2022-08-09 09:23:07 -03:00
case $1 in
def)
# Screenshot to file
2022-08-09 10:04:11 -03:00
$screenshot "$DESTFILE"
2022-08-09 09:23:07 -03:00
echo "$DESTFILE"
;;
2022-08-08 20:05:06 -03:00
2022-08-09 09:23:07 -03:00
area)
# Screen area to file
2022-08-09 10:04:11 -03:00
$screenshot -g "$(slurp -d -b 30303088)" "$DESTFILE"
2022-08-09 09:23:07 -03:00
echo "$DESTFILE"
;;
area-clip)
# Screen area to clipboard
2022-08-09 10:04:11 -03:00
$screenshot -g "$(slurp -d -b 30303088)" - | $copy
2022-08-09 09:23:07 -03:00
;;
2022-08-08 20:05:06 -03:00
2022-08-09 09:23:07 -03:00
clip)
# Focused monitor to clipboard
cur_output=$(${pkgs.sway}/bin/swaymsg -t get_outputs |
${pkgs.jq}/bin/jq -r '.[] | select(.focused) | .name')
2022-08-08 20:05:06 -03:00
2022-08-09 09:23:07 -03:00
test -n "$cur_output" &&
2022-08-09 10:04:11 -03:00
$screenshot -o "$cur_output" - | $copy ||
$screenshot - | $copy
2022-08-09 09:23:07 -03:00
;;
esac
2022-08-08 20:05:06 -03:00
''