Skip to content

Instantly share code, notes, and snippets.

@iacchus
Created June 23, 2022 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iacchus/5182b47b221ed74ebcbe0dfa897cd25e to your computer and use it in GitHub Desktop.
Save iacchus/5182b47b221ed74ebcbe0dfa897cd25e to your computer and use it in GitHub Desktop.
Shell script that toggles a program on/off
#!/usr/bin/env zsh
# USAGE:
# $ chmod + x run-toggle.sh
# ./run-toggle.sh <program binary path>
export FULL_COMMAND=${@:1}
export PROGRAM_NAME=$1
export PROGRAM_PID=$(pgrep -u $USER -x $PROGRAM_NAME)
if [[ $PROGRAM_PID ]]; then
killall $PROGRAM_NAME
notify-send $PROGRAM_NAME off
else
notify-send $PROGRAM_NAME on
$FULL_COMMAND & # run in bg
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment