Skip to content

Instantly share code, notes, and snippets.

@SkyzohKey
Created September 18, 2016 00:22
Show Gist options
  • Save SkyzohKey/50fe51397c1dc808a2c4e3fe2f2b1acf to your computer and use it in GitHub Desktop.
Save SkyzohKey/50fe51397c1dc808a2c4e3fe2f2b1acf to your computer and use it in GitHub Desktop.
This alias permits to add a stop command to your shell. Add it at the end of your `.bashrc/.zshrc/.fishrc/whatever` then `$ source $HOME/.zshrc` and enjoy the `stop` command!
###
# stop - Permits to stop an app with a single command.
# @usage: stop {process-name}
# @exemple: stop firefox
###
function alias_stop() {
APP=$1
PID=$(pidof $@)
# If no app(s) name is/are given, exit.
if [ -z "$APP" ]; then
tput bold; tput setaf 2; echo -e "Usage: stop {process-name}"
tput setaf 4; echo -e "Exemple: $ stop firefox"
return 1
fi
# If the app(s) is/are not running, exit.
if [ -z "$PID" ]; then
tput bold; tput setaf 1; echo -e "${APP} can't be killed because it is not running."
return 1
fi
# Let's kill that/those fucking app(s) 3:D
kill $(pidof $APP)
# Inform the user wheter or not tha app(s) has been killed.
PROC=$(pidof $PID)
if [ -z "$PROC" ]; then
tput bold; tput setaf 2; echo -e "[pid: ${PID}] ${APP} has been stopped. Success!"
return 0
else
tput bold; tput setaf 1; echo -e "[pid: ${PID}] ${APP} can't be killed. Try again."
return 1
fi
}
alias stop=alias_stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment