From 051095fc8334dea0cd6d521152f222b454071c84 Mon Sep 17 00:00:00 2001 From: Aaron Ball Date: Fri, 15 Oct 2021 14:59:43 -0600 Subject: screenshot:refactor and support Wayland This refactors screenshot somewhat so it uses better variable names, curly brace syntax, and quotes. It also better handles being called when a display manager can't be detected. This also adds support for wayland, with a second set of requirements for `grim` and `slurp` if Wayland is detected as the display manager. --- screenshot.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/screenshot.sh b/screenshot.sh index e3b638d..02dca78 100755 --- a/screenshot.sh +++ b/screenshot.sh @@ -3,20 +3,31 @@ # A simple screenshot script. Very handy for calling a specific from a window # manager using custom hotkeys (eg: i3) # -# Requirements: +# Requirements (X11): # imagemagick # -savePath=~/Pictures/screenshots/ +# Requirements (Wayland): +# slurp (for getting screenshot geometry) +# grim (for taking the actual screenshot) +# +savepath=~/Pictures/screenshots/ -if [[ ! -d $savePath ]]; then - mkdir -p $savePath +if [ ! -d "${savepath}" ]; then + mkdir -p "${savepath}" fi # Wait two seconds -sleep 2; +sleep 2 # Get our file suffix -date=`date '+%Y%m%d-%H%M%S'` +date="$(date '+%Y%m%d-%H%M%S')" # And action! -import $savePath/screen.$date.jpg +if [ -n "${WAYLAND_DISPLAY}" ]; then + grim -g "$(slurp -w 4)" "${savepath}/screen.${date}.jpg" +elif [ -n "${DISPLAY}" ]; then + import "${savepath}/screen.${date}.jpg" +else + printf 'ERROR: Could not detect display manager\n' + exit 1 +fi -- cgit v1.2.3