neodotfiles/user/.config/fuzzel/scripts/fuzz_scrot
2024-03-11 01:55:31 -04:00

209 lines
5.5 KiB
Bash
Executable file

#!/usr/bin/env bash
# ***This script was made by Clay Gomera (Drake)***
# - Description: A simple screenshot menu script for rofi/dmenu/wofi
# - Dependencies: {rofi||dmenu||wofi}, grim, slurp
###########################
## Screenshots Directory ##
###########################
SHOTDIR="$XDG_PICTURES_DIR/Screenshots"
[ ! -d "$SHOTDIR" ] && mkdir -p "$SHOTDIR" || echo
#######################
## Main menu choices ##
#######################
mcho1="󱣴 Entire screen"
mcho2="󱎫 Entire screen with delay"
mcho3="󱕻 Select region"
mcho4="󰖯 Active window"
mcho5="󱎘 Exit"
mchos="$mcho1\n$mcho2\n$mcho3\n$mcho4\n$mcho5"
########################
## Screenshot submenu ##
########################
sscho1="󰆏 Copy to clipboard"
sscho2="󰠘 Save to $XDG_PICTURES_DIR"
sscho3="󱎘 Exit"
sschos="$sscho1\n$sscho2\n$sscho3"
#################################
## Screenshot delay subsubmenu ##
#################################
del1="󱑀 3 sec delay"
del2="󱑂 5 sec delay"
del3="󱑇 10 sec delay"
del4="󱎘 Exit"
dels="$del1\n$del2\n$del3\n$del4"
#####
## This function uses the sschos variable
## to ask the user what to do with the
## screenshot
#####
## param: none
## return: string
#####
fsschos() {
sschoice=$(echo -e "$sschos" | $RUNNER -i -l 4 -p "[ What do you want to do with this screenshot?]")
}
#####
## This function uses the dels variable
## to ask the user which delay option to
## choose
#####
## param: none
## return: string
#####
fdel() {
del=$(echo -e "$dels" | $RUNNER -l 5 -i -p "[ Select Delay]")
}
#####
## This function does a full screen
## screenshot without delay, depending on
## what the user chooses on the fsschos
## function, the screenshot will be saved
## to the clipboard or to $SHOTDIR
#####
## param: none
## return: void
#####
shot_screen() {
fsschos
if [ "$sschoice" = "$sscho1" ]; then
sleep 0.5 && grim - | wl-copy && notify-send "Screenshot copied to clipboard"
elif [ "$sschoice" = "$sscho2" ]; then
sleep 0.5 && grim "$SHOTDIR/$(date +%s).png" && notify-send "Screenshot saved to $SHOTDIR"
else
exit 0
fi
}
#####
## This function does a full screen
## screenshot with delay, depending on
## what the user chooses on the fsschos
## function, the screenshot will be saved
## to the clipboard or to $SHOTDIR. And
## depending on what the user chooses on
## the fdel function, the delay will be
## between 3 and 10 seconds
#####
## param: none
## return: void
#####
shot_screen_delay() {
fsschos;
if [ "$sschoice" = "$sscho1" ]; then
fdel;
case $del in
"$del1")
sleep 3 && grim - | wl-copy && notify-send "Screenshot saved to clipboard";
;;
"$del2")
sleep 5 && grim - | wl-copy && notify-send "Screenshot saved to clipboard";
;;
"$del3")
sleep 10 && grim - | wl-copy && notify-send "Screenshot saved to clipboard";
;;
"$del4")
exit 0;
esac
elif [ "$sschoice" = "$sscho2" ]; then
fdel;
case $del in
"$del1")
sleep 3 && grim "$SHOTDIR/$(date +%s).png" && notify-send "Screenshot saved to $SHOTDIR";
;;
"$del2")
sleep 5 && grim "$SHOTDIR/$(date +%s).png" && notify-send "Screenshot saved to $SHOTDIR";
;;
"$del3")
sleep 10 && grim "$SHOTDIR/$(date +%s).png" && notify-send "Screenshot saved to $SHOTDIR";
;;
"$del4")
exit 0;
esac
else
exit 0
fi
}
#####
## This function allows the user to select
## the area on screen to screenshot
## depending on what the user chooses on
## the fsschos function, the screenshot
## will be saved to the clipboard or to
## $SHOTDIR
#####
## param: none
## return: void
#####
shot_area() {
fsschos;
if [ "$sschoice" = "$sscho1" ]; then
sleep 0.5 && grim -g "$(slurp)" - | wl-copy && notify-send "Screenshot saved to clipboard";
elif [ "$sschoice" = "$sscho2" ]; then
sleep 0.5 && grim -g "$(slurp)" "$SHOTDIR/$(date +%s).png" && notify-send "Screenshot saved to $SHOTDIR";
else
exit 0
fi
}
#####
## This function does an screnshot of the
## currently active window, depending on
## what the user chooses on the fsschos
## function, the screenshot will be saved
## to the clipboard or to $SHOTDIR
#####
## param: none
## return: void
#####
shot_window() {
fsschos;
local focused=$(hyprctl activewindow -j)
local geom=$(echo "$focused" | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"')
if [ "$sschoice" = "$sscho1" ]; then
sleep 0.5 && grim -g "$geom" - | wl-copy && notify-send "Screenshot saved to clipboard";
elif [ "$sschoice" = "$sscho2" ]; then
sleep 0.5 && grim -g "$geom" "$SHOTDIR/$(date +%s).png" && notify-send "Screenshot saved to $SHOTDIR";
else
exit 0
fi
}
# show the help output with --help or -h arguments
if [ "$1" == '--help' ] || [ "$1" = '-h' ]; then
echo "fuzz_scrot"
echo "USAGE: rs-scrot [OPTION]"
echo -e "(no option)\tshow the screenshot menu"
echo -e "-h, --help\tthis screen"
exit 1
fi
##########
## main ##
##########
mchoice=$(echo -e "$mchos" | $RUNNER -i -l 5 -p "[ Screenshot Utility]") # main menu prompt
case $mchoice in
"$mcho1")
shot_screen;
;;
"$mcho2")
shot_screen_delay;
;;
"$mcho3")
shot_area;
;;
"$mcho4")
shot_window;
;;
"$mcho5")
exit 0
esac