Cleanup sxmo_screenshot
This commit is contained in:
@@ -2,41 +2,74 @@
|
|||||||
# scrot refuses to work with double quotes
|
# scrot refuses to work with double quotes
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
exitMsg() {
|
exitMsg() {
|
||||||
echo "$1" > /dev/stderr
|
printf "%s\n" "$1" > /dev/stderr
|
||||||
notify-send "$1"
|
notify-send "$1"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
commandExists() {
|
commandExists() {
|
||||||
command -v "$1" 2>/dev/null
|
command -v "$1" > /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$(sxmo_wm.sh)" in
|
swayscreenshot() {
|
||||||
sway)
|
|
||||||
commandExists grim || exitMsg "grim command must be available to take a screenshot."
|
commandExists grim || exitMsg "grim command must be available to take a screenshot."
|
||||||
FILENAME="$(date +%Y-%m-%d-%T)_grim.png"
|
|
||||||
if [ "$1" = "selection" ]; then
|
if [ "$1" = selection ]; then
|
||||||
commandExists slurp || exitMsg "slurp command must be available to make a selection."
|
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)"
|
notify-send "select an area"
|
||||||
|
set -- grim -g "$(slurp)"
|
||||||
else
|
else
|
||||||
COMMAND="grim ~/$FILENAME && (printf ~/$FILENAME | wl-copy)"
|
set -- grim
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
"$@" "$FILENAME"
|
||||||
|
}
|
||||||
|
|
||||||
|
xorgscreenshot() {
|
||||||
|
commandExists scrot || exitMsg "scrot command must be available to take a screenshot"
|
||||||
|
if [ "$1" = "selection" ]; then
|
||||||
|
notify-send 'select an area'
|
||||||
|
set -- scrot -d 1 -q 1 -s
|
||||||
|
else
|
||||||
|
set -- scrot -d 1 -q 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
"$@" "$FILENAME"
|
||||||
|
}
|
||||||
|
|
||||||
|
screenshot() {
|
||||||
|
case "$WM" in
|
||||||
|
sway)
|
||||||
|
swayscreenshot "$@"
|
||||||
;;
|
;;
|
||||||
xorg|dwm)
|
xorg|dwm)
|
||||||
commandExists scrot || exitMsg "scrot command must be available to take a screenshot"
|
xorgscreenshot "$@"
|
||||||
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)
|
ssh)
|
||||||
exitMsg "cannot screenshot ssh ;)"
|
exitMsg "cannot screenshot ssh"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
filepathoutput() {
|
||||||
|
printf %s "$FILENAME"
|
||||||
|
case "$WM" in
|
||||||
|
sway)
|
||||||
|
wl-copy "$FILENAME"
|
||||||
|
;;
|
||||||
|
xorg|dwm)
|
||||||
|
printf %s "$FILENAME" | xsel -b -i
|
||||||
|
|
||||||
eval "$COMMAND" && notify-send "screenshot saved, filename copied to clipboard" && exit 0
|
;;
|
||||||
exitMsg "Screenshot process failure."
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
FILENAME="${SXMO_SCREENSHOT_DIR:-$HOME/$(date +%Y-%m-%d-%T).png}"
|
||||||
|
|
||||||
|
WM="$(sxmo_wm.sh)"
|
||||||
|
|
||||||
|
screenshot "$@"
|
||||||
|
filepathoutput
|
||||||
|
Reference in New Issue
Block a user