diff options
Diffstat (limited to 'contrib/grimshot')
-rwxr-xr-x | contrib/grimshot | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/contrib/grimshot b/contrib/grimshot index 461a5eef..d42fe9d8 100755 --- a/contrib/grimshot +++ b/contrib/grimshot | |||
@@ -13,18 +13,32 @@ | |||
13 | ## See `man 1 grimshot` or `grimshot usage` for further details. | 13 | ## See `man 1 grimshot` or `grimshot usage` for further details. |
14 | 14 | ||
15 | getTargetDirectory() { | 15 | getTargetDirectory() { |
16 | test -f ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs && \ | 16 | test -f "${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs" && \ |
17 | . ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs | 17 | . "${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs" |
18 | 18 | ||
19 | echo ${XDG_SCREENSHOTS_DIR:-${XDG_PICTURES_DIR:-$HOME}} | 19 | echo "${XDG_SCREENSHOTS_DIR:-${XDG_PICTURES_DIR:-$HOME}}" |
20 | } | 20 | } |
21 | 21 | ||
22 | if [ "$1" = "--notify" ]; then | 22 | NOTIFY=no |
23 | NOTIFY=yes | 23 | CURSOR= |
24 | shift 1 | 24 | |
25 | else | 25 | while [ $# -gt 0 ]; do |
26 | NOTIFY=no | 26 | key="$1" |
27 | fi | 27 | |
28 | case $key in | ||
29 | -n|--notify) | ||
30 | NOTIFY=yes | ||
31 | shift # past argument | ||
32 | ;; | ||
33 | -c|--cursor) | ||
34 | CURSOR=yes | ||
35 | shift # past argument | ||
36 | ;; | ||
37 | *) # unknown option | ||
38 | break # done with parsing --flags | ||
39 | ;; | ||
40 | esac | ||
41 | done | ||
28 | 42 | ||
29 | ACTION=${1:-usage} | 43 | ACTION=${1:-usage} |
30 | SUBJECT=${2:-screen} | 44 | SUBJECT=${2:-screen} |
@@ -32,13 +46,13 @@ FILE=${3:-$(getTargetDirectory)/$(date -Ins).png} | |||
32 | 46 | ||
33 | if [ "$ACTION" != "save" ] && [ "$ACTION" != "copy" ] && [ "$ACTION" != "check" ]; then | 47 | if [ "$ACTION" != "save" ] && [ "$ACTION" != "copy" ] && [ "$ACTION" != "check" ]; then |
34 | echo "Usage:" | 48 | echo "Usage:" |
35 | echo " grimshot [--notify] (copy|save) [active|screen|output|area|window] [FILE]" | 49 | echo " grimshot [--notify] [--cursor] (copy|save) [active|screen|output|area|window] [FILE|-]" |
36 | echo " grimshot check" | 50 | echo " grimshot check" |
37 | echo " grimshot usage" | 51 | echo " grimshot usage" |
38 | echo "" | 52 | echo "" |
39 | echo "Commands:" | 53 | echo "Commands:" |
40 | echo " copy: Copy the screenshot data into the clipboard." | 54 | echo " copy: Copy the screenshot data into the clipboard." |
41 | echo " save: Save the screenshot to a regular file." | 55 | echo " save: Save the screenshot to a regular file or '-' to pipe to STDOUT." |
42 | echo " check: Verify if required tools are installed and exit." | 56 | echo " check: Verify if required tools are installed and exit." |
43 | echo " usage: Show this message and exit." | 57 | echo " usage: Show this message and exit." |
44 | echo "" | 58 | echo "" |
@@ -67,7 +81,7 @@ notifyError() { | |||
67 | MESSAGE=${1:-"Error taking screenshot with grim"} | 81 | MESSAGE=${1:-"Error taking screenshot with grim"} |
68 | notify -u critical "$TITLE" "$MESSAGE" | 82 | notify -u critical "$TITLE" "$MESSAGE" |
69 | else | 83 | else |
70 | echo $1 | 84 | echo "$1" |
71 | fi | 85 | fi |
72 | } | 86 | } |
73 | 87 | ||
@@ -91,12 +105,12 @@ takeScreenshot() { | |||
91 | FILE=$1 | 105 | FILE=$1 |
92 | GEOM=$2 | 106 | GEOM=$2 |
93 | OUTPUT=$3 | 107 | OUTPUT=$3 |
94 | if [ ! -z "$OUTPUT" ]; then | 108 | if [ -n "$OUTPUT" ]; then |
95 | grim -o "$OUTPUT" "$FILE" || die "Unable to invoke grim" | 109 | grim ${CURSOR:+-c} -o "$OUTPUT" "$FILE" || die "Unable to invoke grim" |
96 | elif [ -z "$GEOM" ]; then | 110 | elif [ -z "$GEOM" ]; then |
97 | grim "$FILE" || die "Unable to invoke grim" | 111 | grim ${CURSOR:+-c} "$FILE" || die "Unable to invoke grim" |
98 | else | 112 | else |
99 | grim -g "$GEOM" "$FILE" || die "Unable to invoke grim" | 113 | grim ${CURSOR:+-c} -g "$GEOM" "$FILE" || die "Unable to invoke grim" |
100 | fi | 114 | fi |
101 | } | 115 | } |
102 | 116 | ||
@@ -113,7 +127,7 @@ elif [ "$SUBJECT" = "area" ] ; then | |||
113 | GEOM=$(slurp -d) | 127 | GEOM=$(slurp -d) |
114 | # Check if user exited slurp without selecting the area | 128 | # Check if user exited slurp without selecting the area |
115 | if [ -z "$GEOM" ]; then | 129 | if [ -z "$GEOM" ]; then |
116 | exit | 130 | exit 1 |
117 | fi | 131 | fi |
118 | WHAT="Area" | 132 | WHAT="Area" |
119 | elif [ "$SUBJECT" = "active" ] ; then | 133 | elif [ "$SUBJECT" = "active" ] ; then |
@@ -132,7 +146,7 @@ elif [ "$SUBJECT" = "window" ] ; then | |||
132 | GEOM=$(swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp) | 146 | GEOM=$(swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp) |
133 | # Check if user exited slurp without selecting the area | 147 | # Check if user exited slurp without selecting the area |
134 | if [ -z "$GEOM" ]; then | 148 | if [ -z "$GEOM" ]; then |
135 | exit | 149 | exit 1 |
136 | fi | 150 | fi |
137 | WHAT="Window" | 151 | WHAT="Window" |
138 | else | 152 | else |
@@ -147,7 +161,7 @@ else | |||
147 | TITLE="Screenshot of $SUBJECT" | 161 | TITLE="Screenshot of $SUBJECT" |
148 | MESSAGE=$(basename "$FILE") | 162 | MESSAGE=$(basename "$FILE") |
149 | notifyOk "$MESSAGE" "$TITLE" | 163 | notifyOk "$MESSAGE" "$TITLE" |
150 | echo $FILE | 164 | echo "$FILE" |
151 | else | 165 | else |
152 | notifyError "Error taking screenshot with grim" | 166 | notifyError "Error taking screenshot with grim" |
153 | fi | 167 | fi |