(bin): rename epicshot and make it more concise

This commit is contained in:
frosty 2024-07-29 04:15:24 -04:00
parent 5641ae97ed
commit 91a7f1ce67
2 changed files with 61 additions and 120 deletions

View file

@ -1,120 +0,0 @@
#!/bin/sh
# Copyright (c) 2024 frosty <passedgoandgot200@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
set -eu
VERSION="1.0.0"
# shellcheck disable=SC1091
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs" ] && . "${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs"
OUTPUT_DIRECTORY=${XDG_SCREENSHOTS_DIR:-${XDG_PICTURES_DIR:-$HOME}}
FILENAME_BASE="screenshot"
FILENAME_DATE_FORMAT="%Y-%m-%d_%H-%M-%S"
QUIET=
COPY=
OVERLAY=
SAVE=
err() {
echo "$@" >&2
}
die() {
err "${0##*/}: $1"
exit 1
}
notify() {
notify-send "${0##*/}" "$@"
}
screenshot_select() {
maim -qsu "$@"
}
screenshot_full() {
maim -qu "$@"
}
usage() {
err "usage: ${0##*/} [-hVqcos] [TYPE] [FILE]"
err
err " -h show this message and exit"
err " -V show version information and exit"
err " -q suppress program output"
err " -c copy image to clipboard"
err " -o overlay image on screen"
err " -s save image to disk"
}
version() {
err "${0##*/} v$VERSION"
err
err "Copyright (c) 2024 frosty <passedgoandgot200@gmail.com>"
err
err "This program is free software: you can redistribute it and/or modify"
err "it under the terms of the GNU General Public License as published by"
err "the Free Software Foundation, either version 3 of the License, or"
err "(at your option) any later version."
}
while getopts :hVqcos opt; do
case $opt in
h)
usage
exit 0
;;
V)
version
exit 0
;;
q) QUIET=1 ;;
c) COPY=1 ;;
o) OVERLAY=1 ;;
s) SAVE=1 ;;
*) die "invalid option: -$OPTARG" ;;
esac
done
shift $((OPTIND - 1))
SCREENSHOT_TYPE=${1:-select}
FILE_PATH=${2:-}
case "$SCREENSHOT_TYPE" in
select | full) ;;
*)
usage
exit 1
;;
esac
if [ -n "$SAVE" ]; then
FILE_PATH=${FILE_PATH:-$OUTPUT_DIRECTORY/$FILENAME_BASE-$(date "+$FILENAME_DATE_FORMAT").png}
else
FILE_PATH="/tmp/${0##*/}-$(date '+%s').png"
fi
screenshot_"$SCREENSHOT_TYPE" "$FILE_PATH" || exit 0
[ -z "$QUIET" ] && notify "Screenshot taken"
[ -n "$COPY" ] && xclip -sel clip -t image/png "$FILE_PATH"
[ -n "$OVERLAY" ] && feh --class no-decor -x "$FILE_PATH"
[ -z "$SAVE" ] && rm "$FILE_PATH"

61
.local/bin/screenshot Executable file
View file

@ -0,0 +1,61 @@
#!/bin/sh
set -eu
# shellcheck disable=SC1091
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs" ] && . "${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs"
OUTPUT_DIRECTORY="${XDG_SCREENSHOTS_DIR:-${XDG_PICTURES_DIR:-$HOME}}"
FILENAME_BASE="screenshot"
FILENAME_DATE_FORMAT="%Y-%m-%d_%H-%M-%S"
QUIET=
COPY=
SAVE=
die() {
printf '%s: %s\n' "${0##*/}" "$1"
exit 1
}
notify() {
notify-send "${0##*/}" "$@"
}
screenshot_select() {
maim -qsu "$@"
}
screenshot_full() {
maim -qu "$@"
}
while getopts :hVqcos opt; do
case "$opt" in
q) QUIET=1 ;;
c) COPY=1 ;;
s) SAVE=1 ;;
*) die "invalid option: -$OPTARG" ;;
esac
done
shift "$((OPTIND - 1))"
SCREENSHOT_TYPE="${1:-full}"
FILE_PATH="${2:-}"
case "$SCREENSHOT_TYPE" in
select | full) ;;
*) exit 1 ;;
esac
if [ -n "$SAVE" ]; then
FILE_PATH="${FILE_PATH:-$OUTPUT_DIRECTORY/$FILENAME_BASE-$(date "+$FILENAME_DATE_FORMAT").png}"
else
FILE_PATH="/tmp/${0##*/}-$(date '+%s').png"
fi
screenshot_"$SCREENSHOT_TYPE" "$FILE_PATH" || exit 0
[ -z "$QUIET" ] && notify "Screenshot taken."
[ -n "$COPY" ] && xclip -sel clip -t image/png "$FILE_PATH"
[ -z "$SAVE" ] && rm "$FILE_PATH"