1
0
mirror of https://github.com/frebib/dotfiles.git synced 2024-06-14 12:57:23 +00:00

scripts/screenshot: add proper arg parsing

This fixes usage of --active and --clip together. I'm not even sure how
it worked before this tbh.

Signed-off-by: Joe Groocock <me@frebib.net>
This commit is contained in:
Joe Groocock 2020-08-11 09:04:41 +01:00
parent 0bf16821d5
commit 715349d0f4
Signed by: frebib
GPG Key ID: E0B16BEACFBB6A86
2 changed files with 43 additions and 18 deletions

View File

@ -145,7 +145,9 @@ bindsym $mod+Shift+p exec rofi-pass --root $(grep path ~/.config/gopa
bindsym $mod+Shift+e exec "pkill rofi; rofi -show emoji -modi emoji -normal-window" bindsym $mod+Shift+e exec "pkill rofi; rofi -show emoji -modi emoji -normal-window"
bindsym $mod+Shift+i exec rofi-fontawesome bindsym $mod+Shift+i exec rofi-fontawesome
bindsym --release Print exec screenshot bindsym --release Print exec screenshot
bindsym --release $mod+Print exec imgur-screenshot bindsym --release $mod+Print exec screenshot --clip
bindsym --release Shift+Print exec screenshot --active
bindsym --release $mod+Shift+Print exec screenshot --active --clip
bindsym $mod+Shift+x exec systemd-run-i3 -n i3-sensible-terminal --class floating-term --hold -e /bin/echo "$(xprop -id $(xdotool getactivewindow))" bindsym $mod+Shift+x exec systemd-run-i3 -n i3-sensible-terminal --class floating-term --hold -e /bin/echo "$(xprop -id $(xdotool getactivewindow))"
bindsym $mod+$alt+space exec systemd-run-i3 -n ~/.config/i3/cycleaudio.py && pkill -RTMIN+10 i3blocks bindsym $mod+$alt+space exec systemd-run-i3 -n ~/.config/i3/cycleaudio.py && pkill -RTMIN+10 i3blocks
bindsym $mod+numbersign exec systemd-run-i3 -n i3-sensible-terminal --hold -e sh -c 'xclip -o | gpg --decrypt 2>&1' bindsym $mod+numbersign exec systemd-run-i3 -n i3-sensible-terminal --hold -e sh -c 'xclip -o | gpg --decrypt 2>&1'

View File

@ -13,6 +13,29 @@ URL_PATH=https://frebib.net/s
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
params=$(getopt -o ac -l active,clip -n screenshot -- "$@")
eval set -- "$params"
unset params
while true; do
case "$1" in
'-a'|'--active')
active=1
shift
continue;;
'-c'|'--clip')
clip=1
shift
continue;;
'--')
shift
break;;
*)
echo 'getopt error' >&2
exit 1;;
esac
done
send_notification() { send_notification() {
title="$1" title="$1"
body="$2" body="$2"
@ -28,24 +51,24 @@ send_notification() {
# Make the screenshot directory # Make the screenshot directory
mkdir -p "$DIRECTORY" mkdir -p "$DIRECTORY"
# Take screenshot geometry
read -r winid geom < <(slop -f "%i %g") || :
if [ -z "$geom" -o -z "$winid" ]; then
send_notification "Screenshot error" "Failed to capture screenshot area" > /dev/null
exit 1
fi
out_path="$DIRECTORY/$FILENAME" out_path="$DIRECTORY/$FILENAME"
args=(-g "$geom")
# If selection is the root window if [ "$active" = '1' ]; then
if xwininfo -id "$winid" | grep -qw root; then
isroot=1
args+=(-i "$winid")
elif [ "$1" == "--active" -o "$1" == "-a" ]; then
args+=(-i "$(xdotool getactivewindow)") args+=(-i "$(xdotool getactivewindow)")
shift else
# Take screenshot geometry
read -r winid geom < <(slop -f "%i %g") || :
if [ -z "$geom" -o -z "$winid" ]; then
send_notification "Screenshot error" "Failed to capture screenshot area" > /dev/null
exit 1
fi
args=(-g "$geom")
# If selection is the root window
if xwininfo -id "$winid" | grep -qw root; then
isroot=1
args+=(-i "$winid")
fi
fi fi
# Take the screenshot and save it # Take the screenshot and save it
@ -60,10 +83,10 @@ if [ "$isroot" != "1" ]; then
convert "$out_path" \( +clone -background black -alpha set -channel Alpha -evaluate set 60% -shadow 100x16+0+0 \) +swap -background none -layers merge +repage "$out_path" || : convert "$out_path" \( +clone -background black -alpha set -channel Alpha -evaluate set 60% -shadow 100x16+0+0 \) +swap -background none -layers merge +repage "$out_path" || :
fi fi
if [ "$1" == "--clip" -o "$1" == "-c" ]; then if [ "$clip" = '1' ]; then
# Add image to clipboard # Add image to clipboard
xclip -i "$out_path" -selection clipboard -t image/png xclip -i "$out_path" -selection clipboard -t image/png
send_notification "Screenshot captured" "$FILENAME<br><br>The image is available in the clipboard" send_notification "Screenshot captured" "$FILENAME<br><br>The image is available in the clipboard" >/dev/null
exit 0 exit 0
fi fi