mirror of
https://github.com/swaywm/sway.git
synced 2025-10-31 22:25:26 -04:00
Support cursor capture in grimshot
Refactor argument parser Bring back `sh` compatibility Default to NOTIFY=no
This commit is contained in:
parent
2dace6b824
commit
a5f01a0e04
3 changed files with 43 additions and 21 deletions
|
|
@ -13,18 +13,32 @@
|
|||
## See `man 1 grimshot` or `grimshot usage` for further details.
|
||||
|
||||
getTargetDirectory() {
|
||||
test -f ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs && \
|
||||
. ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs
|
||||
test -f "${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs" && \
|
||||
. "${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs"
|
||||
|
||||
echo ${XDG_SCREENSHOTS_DIR:-${XDG_PICTURES_DIR:-$HOME}}
|
||||
echo "${XDG_SCREENSHOTS_DIR:-${XDG_PICTURES_DIR:-$HOME}}"
|
||||
}
|
||||
|
||||
if [ "$1" = "--notify" ]; then
|
||||
NOTIFY=yes
|
||||
shift 1
|
||||
else
|
||||
NOTIFY=no
|
||||
fi
|
||||
NOTIFY=no
|
||||
CURSOR=
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
key="$1"
|
||||
|
||||
case $key in
|
||||
-n|--notify)
|
||||
NOTIFY=yes
|
||||
shift # past argument
|
||||
;;
|
||||
-c|--cursor)
|
||||
CURSOR=yes
|
||||
shift # past argument
|
||||
;;
|
||||
*) # unknown option
|
||||
break # done with parsing --flags
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
ACTION=${1:-usage}
|
||||
SUBJECT=${2:-screen}
|
||||
|
|
@ -32,7 +46,7 @@ FILE=${3:-$(getTargetDirectory)/$(date -Ins).png}
|
|||
|
||||
if [ "$ACTION" != "save" ] && [ "$ACTION" != "copy" ] && [ "$ACTION" != "check" ]; then
|
||||
echo "Usage:"
|
||||
echo " grimshot [--notify] (copy|save) [active|screen|output|area|window] [FILE|-]"
|
||||
echo " grimshot [--notify] [--cursor] (copy|save) [active|screen|output|area|window] [FILE|-]"
|
||||
echo " grimshot check"
|
||||
echo " grimshot usage"
|
||||
echo ""
|
||||
|
|
@ -67,7 +81,7 @@ notifyError() {
|
|||
MESSAGE=${1:-"Error taking screenshot with grim"}
|
||||
notify -u critical "$TITLE" "$MESSAGE"
|
||||
else
|
||||
echo $1
|
||||
echo "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
@ -91,12 +105,12 @@ takeScreenshot() {
|
|||
FILE=$1
|
||||
GEOM=$2
|
||||
OUTPUT=$3
|
||||
if [ ! -z "$OUTPUT" ]; then
|
||||
grim -o "$OUTPUT" "$FILE" || die "Unable to invoke grim"
|
||||
if [ -n "$OUTPUT" ]; then
|
||||
grim ${CURSOR:+-c} -o "$OUTPUT" "$FILE" || die "Unable to invoke grim"
|
||||
elif [ -z "$GEOM" ]; then
|
||||
grim "$FILE" || die "Unable to invoke grim"
|
||||
grim ${CURSOR:+-c} "$FILE" || die "Unable to invoke grim"
|
||||
else
|
||||
grim -g "$GEOM" "$FILE" || die "Unable to invoke grim"
|
||||
grim ${CURSOR:+-c} -g "$GEOM" "$FILE" || die "Unable to invoke grim"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
@ -147,7 +161,7 @@ else
|
|||
TITLE="Screenshot of $SUBJECT"
|
||||
MESSAGE=$(basename "$FILE")
|
||||
notifyOk "$MESSAGE" "$TITLE"
|
||||
echo $FILE
|
||||
echo "$FILE"
|
||||
else
|
||||
notifyError "Error taking screenshot with grim"
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue