diff options
author | Aaron Ball <nullspoon@oper.io> | 2021-10-15 14:59:43 -0600 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2021-10-15 14:59:43 -0600 |
commit | 051095fc8334dea0cd6d521152f222b454071c84 (patch) | |
tree | 9a2be59b7910e537e922e320d9d065c5b5db24d3 | |
parent | efd616302e739feb9a1bb81466287f41506df4a5 (diff) | |
download | bin-051095fc8334dea0cd6d521152f222b454071c84.tar.gz bin-051095fc8334dea0cd6d521152f222b454071c84.tar.xz |
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.
-rwxr-xr-x | screenshot.sh | 25 |
1 files 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 |