Created
November 9, 2011 21:27
-
-
Save chorn/1353103 to your computer and use it in GitHub Desktop.
I use this in my .bashrc so I can start/stop homebrew installed daemons via a 3 letter prefix. ``start mys'' for mysql. ``stop red'' for redis, etc.
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
| simple_launchctl() { | |
| command=$1 | |
| server=$2 | |
| for plist in ~/Library/LaunchAgents/*.plist ; do | |
| if [[ `grep -c Cellar "${plist}"` -ne 0 ]] ; then | |
| abbrev=`echo $plist | sed -E -e 's/^.*\///' -e 's/^[[:alnum:]]*\.[[:alnum:]]*\.//' -e 's/\.plist$//' -e 's/([[:alnum:]][[:alnum:]][[:alnum:]]).*/\1/'` | |
| if [[ "$server" == "$abbrev" ]] ; then | |
| launchctl $command -w "${plist}" | |
| return | |
| fi | |
| fi | |
| done | |
| } | |
| start() { simple_launchctl "load" $1 ;} | |
| stop() { simple_launchctl "unload" $1 ;} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's some serious bash/sed voodoo for saving typing two characters ;-)