rc/bin/shot

27 lines
768 B
Text
Raw Permalink Normal View History

2019-11-20 23:58:51 +00:00
#!/bin/sh
# Load helper functions
bin_path="$(dirname "$(rreadlink "$0")")"
source "$bin_path/../lib/utils.sh"
2019-11-20 23:58:51 +00:00
if [ -z "$1" ]; then
NAME="shot_$(date '+%Y%m%d%H%M%S').png"
else
NAME="$1"
fi
SCREEN_DIR="$HOME/img/screenshots"
mkdir -p "$SCREEN_DIR"
# Let's try to detect Wayland running
if [ -z "$WAYLAND_DISPLAY" ]; then
assert_exists "maim"
2020-11-20 18:12:53 +00:00
maim --hidecursor --select "$SCREEN_DIR/$NAME"
2019-11-20 23:58:51 +00:00
# Fail silently if xsel isn't installed, the clipboard feature isn't critical
2020-11-20 18:12:53 +00:00
echo "$SCREEN_DIR/$NAME" | xsel --clipboard --input > /dev/null 2>&1
2019-11-20 23:58:51 +00:00
else
assert_exists "grim" "slop"
2019-11-20 23:58:51 +00:00
slop | awk -F '[x+]' '{printf "%s,%s %sx%s",$3,$4,$1,$2}' | grim -g - "$SCREEN_DIR/$NAME"
# Same as xsel
wl-copy -n "$SCREEN_DIR/$NAME" > /dev/null 2>&1
fi