nix-config/systems/x86_64-linux/navis/screenshot/default.nix

86 lines
2.4 KiB
Nix
Raw Normal View History

2024-05-16 02:40:39 -04:00
{pkgs, ...}:
with pkgs; {
home.packages = [
(writeScriptBin "screenshot" ''
notify_user() {
${pulseaudio}/bin/paplay ${sound-theme-freedesktop}/share/sounds/freedesktop/stereo/screen-capture.oga 2>/dev/null &
${libnotify}/bin/notify-send \
-a Clipboard \
-i ${builtins.toString ./clipboard.svg} \
-u low \
-r 699 "Clipboard" "Screenshot saved on clipboard"
}
screen() {
${maim}/bin/maim -u -f png | ${pkgs.xclip}/bin/xclip -selection clipboard -t image/png
notify_user
}
window() {
2024-05-28 04:08:06 -04:00
window_geometry=$(${xdotool}/bin/xdotool getwindowgeometry $(${xdotool}/bin/xdotool getactivewindow) | tail -n +2 | awk '{print $2}' | tac)
last_line=$(echo "$window_geometry" | tail -n 1)
modified_last_line=$(echo "$last_line" | awk 'BEGIN {FS=OFS=","} {for(i=1; i<=NF; i++) $i+=2; print}' | sed -E "s/([+-]?[0-9]+),([+-]?[0-9]+)/+\1+\2/g; s/\+\-/\-/g")
final_string=$(echo "$window_geometry" | sed '$s/.*/'"$modified_last_line"'/' | paste -sd "")
${maim}/bin/maim -u -f png -g "$final_string" | ${pkgs.xclip}/bin/xclip -selection clipboard -t image/png
2024-05-16 02:40:39 -04:00
notify_user
}
area() {
${maim}/bin/maim -u -f png -s -b 2 -c 0.35,0.55,0.85,0.25 -l | ${pkgs.xclip}/bin/xclip -selection clipboard -t image/png
notify_user
}
menu() {
screen="󰍹"
area="󰒉"
window=""
chosen="$(printf "%s\n%s\n%s\n%s\n" "$screen" "$area" "$window" | rofi -theme ${builtins.toString ./screenshot.rasi} -p 'Take Screenshot' -dmenu -selected-row 0 -theme-str 'listview {lines: 3;}')"
case $chosen in
"$screen")
screen
;;
"$area")
area
;;
"$window")
window
;;
esac
}
docs() {
echo "
Usage: screenshot [Options]
--help - Prints this message
Options:
--screen - Take screenshot of the screen
--window - Take screenshot of the focused window
--area - Take screenshot of the selected area
--menu - Opens a gui selector
"
}
case $1 in
--screen)
screen
;;
--window)
window
;;
--area)
area
;;
--menu)
menu
;;
--help | *)
docs
;;
esac
'')
];
}