Screenshot interface is way better

This commit is contained in:
Sasha Koshka 2024-01-31 11:35:11 -05:00
parent d14b748536
commit 75b2b6e0b2

View File

@ -1,35 +1,58 @@
#!/bin/sh
if ! type scrot > /dev/null; then
>&2 echo "!!! scrot is not installed"
name=`basename "$0"`
isInstalled() {
type "$1" > /dev/null
}
mustHaveInstalled() {
if ! isInstalled "$1"; then
echo "$name: $1 is not installed" >&2
exit 1
fi
fi
}
usage() {
echo "Usage: $name [selection | window | screen] [clipboard]" >&2
exit 2
}
picturesDir=`xdg-user-dir PICTURES`
test -z "$picturesDir" && picturesDir="$HOME/Pictures"
picturesDir="$picturesDir/Screen Shots"
if ! mkdir -p "$picturesDir"; then
>&2 echo "!!! can't create $picturesDir"
echo "$name: can't create $picturesDir" >&2
exit 1
fi
output="$picturesDir/`date -Iseconds`.png"
outputFilePath="$picturesDir/`date -Iseconds`.png"
mustHaveInstalled scrot
case "$1" in
"selection")
scrot --select --line style=dash --freeze --file "$output"
clipArg="$2"
;;
"window")
scrot --focused --border --file "$output"
clipArg="$2"
"selection" | "window" | "screen")
mode="$1"
shift 1
;;
*)
scrot --file "$output"
clipArg="$1"
mode="screen"
;;
esac
if test "$clipArg" = "clipboard"; then
xclip -selection clipboard -target image/png -i "$output"
if [ "$1" = "clipboard" ]; then
clipboard=true
shift 1
fi
[ "$#" -gt 0 ] && usage
case "$mode" in
"selection") scrot --select --line style=dash --freeze --file "$output";;
"window" ) scrot --focused --border --file "$output";;
"screen" ) scrot --file "$output";;
esac
if [ -n "$copyToClipboard" ]; then
mustHaveInstalled xclip
xclip -selection clipboard -target image/png -i "$outputFilePath"
fi