Screenshot: Copy path to clipboard in wayland, rework script for better error detection

also, ostensibly fix clipboard copying for x

Signed-off-by: Stacy Harper <contact@stacyharper.net>
This commit is contained in:
Zach DeCook
2021-10-21 02:34:42 -04:00
committed by Stacy Harper
parent 86242011a1
commit 576550451d
2 changed files with 29 additions and 13 deletions

View File

@@ -2,25 +2,41 @@
# scrot refuses to work with double quotes
# shellcheck disable=SC2016
exitMsg(){
echo "$1" > /dev/stderr
notify-send "$1"
exit 1
}
commandExists(){
command -v "$1" 2>/dev/null
}
case "$(sxmo_wm.sh)" in
sway)
commandExists grim || exitMsg "grim command must be available to take a screenshot."
FILENAME="$(date +%Y-%m-%d-%T)_grim.png"
SELECTION="slurp | grim -g - ~/$FILENAME"
WHOLESCREEN="grim ~/$FILENAME"
if [ "$1" = "selection" ]; then
commandExists slurp || exitMsg "slurp command must be available to make a selection."
COMMAND="notify-send 'select an area' && slurp | grim -g - ~/$FILENAME && (printf ~/$FILENAME | wl-copy)"
else
COMMAND="grim ~/$FILENAME && (printf ~/$FILENAME | wl-copy)"
fi
;;
xorg|dwm)
SELECTION="scrot -e 'echo $f | xsel -i -b' -d 1 -s -q 1"
WHOLESCREEN="scrot -e 'echo $f | xsel -i -b' -d 1 -q 1"
commandExists scrot || exitMsg "scrot command must be available to take a screenshot"
f='$f'
if [ "$1" = "selection" ]; then
COMMAND="notify-send 'select an area' && scrot -e 'echo $f | xsel -i -b' -d 1 -s -q 1"
else
COMMAND="scrot -e 'echo $f | xsel -i -b' -d 1 -q 1"
fi
;;
ssh)
echo "cannot screenshot ssh ;)"
exit 0
exitMsg "cannot screenshot ssh ;)"
;;
esac
if [ "$1" = "selection" ]; then
notify-send "select an area" && eval "$SELECTION" && notify-send "screenshot saved, filename copied to clipboard"
else
eval "$WHOLESCREEN" && notify-send "screenshot saved, filename copied to clipboard"
fi
eval "$COMMAND" && notify-send "screenshot saved, filename copied to clipboard" && exit 0
exitMsg "Screenshot process failure."