Created
November 29, 2017 20:39
-
-
Save sillyslux/1bdf2be168fe25a17baa48750f6f808d to your computer and use it in GitHub Desktop.
a few shell functions
This file contains 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
#!/bin/sh | |
# descr: chainable "isRunning" functions | |
# Usage: R conky && echo "conky is running" || echo "conky is not running" | |
# S conky && echo "do something with $pid and $pcmd" || echo "do something else" | |
# simple isRunning function | |
R () { | |
pidof $1 > /dev/null | |
return $? | |
} | |
# sophisicated isRunning function (also sets $pid and $pcmd) | |
S () { | |
pid=$(pidof -s $1) | |
pcmd=$([ $pid ] && ps --no-headers -o cmd -q $pid) | |
return $? | |
} |
This file contains 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
#!/bin/sh | |
# descr: restart programs with shell functions | |
# usage: RS conky && echo "conky restarted" || echo "conky wasn't running" | |
# RA conky && echo "all conkies restarted" || echo "there was no running conky" | |
# restart first found instance of some program | |
RS () { | |
pid=$(pidof -s $1) | |
pcmd=$([ $pid ] && ps --no-headers -o cmd -q $pid) | |
[ $pid ] && kill $pid && sh -c "$pcmd" | |
return $? | |
} | |
# restart all instances of some program | |
RA () { | |
for pid in $(pidof $1); do | |
pcmd=$(ps --no-headers -o cmd -q $pid) | |
kill $pid && sh -c "$pcmd" | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment