Created
June 23, 2022 04:31
-
-
Save iacchus/5182b47b221ed74ebcbe0dfa897cd25e to your computer and use it in GitHub Desktop.
Shell script that toggles a program on/off
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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