feat: added silent arg

This commit is contained in:
Gustavo Parreira 2022-11-10 22:34:06 +00:00
parent 5d65f15e23
commit e66872686a
No known key found for this signature in database
GPG key ID: 461165CBB467DD30

View file

@ -16,6 +16,7 @@ Options:
-o, --output-folder directory in which to save screenshot
-f, --filename the file name of the resulting screenshot
-d, --debug print debug information
-s, --silent don't send notification when screenshot is saved
--clipboard-only copy screenshot to clipboard and don't save image in disk
-- [command] open screenshot with a command of your choosing. e.g. hyprshot -m window -- mirage
@ -30,6 +31,14 @@ function Print() {
[ $DEBUG -eq 1 ] && printf "$@" >&2
}
function send_notification() {
[ $SILENT -eq 0 ] && {
notify-send "Screenshot saved" \
"Image saved in <i>${1}</i> and copied to the clipboard." \
-i "${1}"
}
}
function save_geometry() {
[ -z "${1}" ] && Print "no geometry\n" && exit 1;
@ -41,9 +50,7 @@ function save_geometry() {
# outside the monitor
convert $output -trim +repage $output
wl-copy < "$output"
notify-send "Screenshot saved" \
"Image saved in <i>$output</i> and copied to the clipboard." \
-i "$output"
send_notification $output
[ -z "$COMMAND" ] || {
"$COMMAND" "$output"
}
@ -81,7 +88,7 @@ function grab_window() {
}
function args() {
local options=$(getopt -o hf:o:m:d --long help,filename:,output-folder:,mode:,clipboard-only,debug -- "$@")
local options=$(getopt -o hf:o:m:ds --long help,filename:,output-folder:,mode:,clipboard-only,debug,silent -- "$@")
[ $? -eq 0 ] || {
Print "Invalid option provided\n"
exit 2
@ -116,6 +123,9 @@ function args() {
-d | --debug)
DEBUG=1
;;
-s | --silent)
SILENT=1
;;
--)
shift # Skip -- argument
COMMAND=${@:2}
@ -137,6 +147,7 @@ function args() {
CLIPBOARD=0
DEBUG=0
SILENT=0
FILENAME="$(date +'%Y-%m-%d-%H%M%S_hyprshot.png')"
[ -z "$HYPRSHOT_DIR" ] && SAVEDIR=${XDG_PICTURES_DIR:=~} || SAVEDIR=${HYPRSHOT_DIR}