Skip to content

Instantly share code, notes, and snippets.

@chorn
Created November 9, 2011 21:27
Show Gist options
  • Select an option

  • Save chorn/1353103 to your computer and use it in GitHub Desktop.

Select an option

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.
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 ;}
@eigenben
Copy link
Copy Markdown

eigenben commented Dec 6, 2011

That's some serious bash/sed voodoo for saving typing two characters ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment