feat: grimshot supports save and copy

Adds new action savecopy which saves then copies

Fixes: 7116
This commit is contained in:
Colin Nelson 2022-11-04 09:09:41 -07:00
parent e40eb338b9
commit 4ad568662d
No known key found for this signature in database
GPG key ID: C7EA5A35EFEEE948

View file

@ -44,7 +44,7 @@ ACTION=${1:-usage}
SUBJECT=${2:-screen}
FILE=${3:-$(getTargetDirectory)/$(date -Ins).png}
if [ "$ACTION" != "save" ] && [ "$ACTION" != "copy" ] && [ "$ACTION" != "check" ]; then
if [ "$ACTION" != "save" ] && [ "$ACTION" != "copy" ] && [ "$ACTION" != "savecopy" ] && [ "$ACTION" != "check" ]; then
echo "Usage:"
echo " grimshot [--notify] [--cursor] (copy|save) [active|screen|output|area|window] [FILE|-]"
echo " grimshot check"
@ -53,6 +53,7 @@ if [ "$ACTION" != "save" ] && [ "$ACTION" != "copy" ] && [ "$ACTION" != "check"
echo "Commands:"
echo " copy: Copy the screenshot data into the clipboard."
echo " save: Save the screenshot to a regular file or '-' to pipe to STDOUT."
echo " savecopy: Saves the screenshot to a regular file and copies the data into the clipboard."
echo " check: Verify if required tools are installed and exit."
echo " usage: Show this message and exit."
echo ""
@ -153,16 +154,22 @@ else
die "Unknown subject to take a screen shot from" "$SUBJECT"
fi
if [ "$ACTION" = "copy" ] ; then
takeScreenshot - "$GEOM" "$OUTPUT" | wl-copy --type image/png || die "Clipboard error"
notifyOk "$WHAT copied to buffer"
else
if takeScreenshot "$FILE" "$GEOM" "$OUTPUT"; then
TITLE="Screenshot of $SUBJECT"
MESSAGE=$(basename "$FILE")
notifyOk "$MESSAGE" "$TITLE"
echo "$FILE"
else
notifyError "Error taking screenshot with grim"
fi
fi
case "$ACTION" in
copy)
takeScreenshot - "$GEOM" "$OUTPUT" | wl-copy --type image/png || die "Clipboard error";
notifyOk "$WHAT copied to buffer";;
save*)
if takeScreenshot "$FILE" "$GEOM" "$OUTPUT"; then
if [ "$ACTION" = "savecopy" ]; then
wl-copy --type image/png < "$FILE" || die "Clipboard error"
fi
TITLE="Screenshot of $SUBJECT"
MESSAGE=$(basename "$FILE")
notifyOk "$MESSAGE" "$TITLE"
echo "$FILE"
else
notifyError "Error taking screenshot with grim"
fi;;
*)
die "Unexpected action: $ACTION"
esac