Skip to content

Commit

Permalink
added -y or --notify flag which sends notifications on error or succe…
Browse files Browse the repository at this point in the history
…ss, xdotool is a hard dependency now, also updated readme and manpages to mention --notify, implements #4
  • Loading branch information
phisch committed Jun 5, 2019
1 parent cc1af4c commit b9006b2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions man/giph.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/giph
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -68,6 +69,7 @@ function log() {
}

function log_error() {
notify "$1" "critical"
log "\033[0;31mERROR:\033[0m $1" -1 "${2:-true}" true
}

Expand All @@ -76,13 +78,23 @@ function log_warning() {
}

function log_success() {
notify "$1" "normal"
log "\033[0;32mSUCCESS:\033[0m $1" 0 "${2:-true}"
}

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
Expand Down Expand Up @@ -132,6 +144,9 @@ while [[ "$1" == -* ]]; do
shift
INTERFACE="$1"
;;
-y|--notify)
NOTIFY=1
;;
-b|--bordersize)
shift
SLOP_BORDERSIZE="$1"
Expand Down

0 comments on commit b9006b2

Please sign in to comment.