Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions src/giph
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

stty -echoctl # don't print ^C when pressing ctrl+c

signal_usr1_handled=false
function handle_usr1(){
# Ensure giph only receives SIGUSR1 ONCE
if [[ -n $FFMPEG_PID && "$signal_usr1_handled" == false ]]; then
signal_usr1_handled=true
kill $FFMPEG_PID
wait $FFMPEG_PID
fi
}

function handle_usr2(){
if [[ -n $FFMPEG_PID ]]; then
kill -KILL $FFMPEG_PID
fi
delete_temporary_directory
exit 1
}

trap handle_usr1 SIGUSR1
trap handle_usr2 SIGUSR2

readonly VERSION=1.1.1

# verbosity
Expand Down Expand Up @@ -49,6 +70,7 @@ OPTIONS
-ms, --microphone-source=STRING Overwrite the default microphone source.
-y, --notify Send notification on error or success.
--stop Finish any running giph recordings.
--kill Abort all giph recordings.

SLOP OPTIONS
-b, --bordersize=FLOAT Set the selection border thickness.
Expand Down Expand Up @@ -130,6 +152,9 @@ while [[ "$1" == -* ]]; do
--stop)
SHOULD_STOP=true
;;
--kill)
SHOULD_KILL=true
;;
-s|--select)
SLOP=1
;;
Expand Down Expand Up @@ -469,14 +494,24 @@ function giph() {
exit 0
}


function stop_all_recordings() {
for pid in "$(pgrep -f "bash.+giph")"; do
kill -INT -$pid
for pid in $(pgrep -f "bash.+giph"); do
kill -USR1 $pid
done
}


function abort_all_recordings() {
for pid in $(pgrep -f "bash.+giph"); do
kill -USR2 $pid
done
}

if [ -n "$SHOULD_STOP" ]; then
stop_all_recordings
elif [ -n "$SHOULD_KILL" ]; then
abort_all_recordings
else
giph
fi
Expand Down