From b9006b2d4499734d55dfc7bbb41a17d3925ddcac Mon Sep 17 00:00:00 2001 From: Philipp Schaffrath Date: Wed, 5 Jun 2019 02:50:10 +0200 Subject: [PATCH] added -y or --notify flag which sends notifications on error or success, xdotool is a hard dependency now, also updated readme and manpages to mention --notify, implements #4 --- README.md | 3 ++- man/giph.1 | 3 +++ src/giph | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2a5fade..2b37477 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,12 @@ $ yay -S giph-git Make sure to install the following dependencies: - ffmpeg + - xdotool Optionally, install the following dependencies: - slop (`--select`) - - xdotool (`--window` or desktop recording) + - libnotify (`--notify`) - zenity (`--interface zenity`) Clone the giph repository: diff --git a/man/giph.1 b/man/giph.1 index 360bab4..958243b 100644 --- a/man/giph.1 +++ b/man/giph.1 @@ -85,6 +85,9 @@ Selects the user interface method that is used for countdown, timer and to stop .br \(bu .IR zenity ": displays control-windows using zenity" +.TP +.BR \-y ", " \-\-notify +Uses notify-send to send an urgent notification if an error happens, or a normal notification when the final gif was saved successfully. .SH SLOP OPTIONS When .BR -s " or " --select diff --git a/src/giph b/src/giph index deb023c..8a034bf 100755 --- a/src/giph +++ b/src/giph @@ -38,6 +38,7 @@ OPTIONS -t, --timer=TIMEDURATION Time of the recording. (e.g. 10 for 10 seconds or 1:30 for 1 minute 30 seconds) -f, --framerate=INT Set the framerate. -i, --interface=STRING Set the user interface that should be used. ("cli" or "zenity") + -y, --notify Send notification on error or success. SLOP OPTIONS -b, --bordersize=FLOAT Set the selection border thickness. @@ -68,6 +69,7 @@ function log() { } function log_error() { + notify "$1" "critical" log "\033[0;31mERROR:\033[0m $1" -1 "${2:-true}" true } @@ -76,6 +78,7 @@ function log_warning() { } function log_success() { + notify "$1" "normal" log "\033[0;32mSUCCESS:\033[0m $1" 0 "${2:-true}" } @@ -83,6 +86,15 @@ function log_info() { log "\033[0;36mINFO:\033[0m $1" 0 "${2:-true}" } +function notify() { + [ "$NOTIFY" = 1 ] && { + notify=(notify-send -t 3000) + notify+=(-u "$2") + notify+=("giph" "$1") + "${notify[@]}" + } +} + if [ -z "$1" ]; then print_help fi @@ -132,6 +144,9 @@ while [[ "$1" == -* ]]; do shift INTERFACE="$1" ;; + -y|--notify) + NOTIFY=1 + ;; -b|--bordersize) shift SLOP_BORDERSIZE="$1"