Skip to content

Instantly share code, notes, and snippets.

@Mic92
Created November 17, 2010 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mic92/703870 to your computer and use it in GitHub Desktop.
Save Mic92/703870 to your computer and use it in GitHub Desktop.
Service control completion for zsh
# This code generate the function start, stop, restart
# which you can use to control your deamons like alsa, hal ...
# To use it, put it in your .zshrc.
# Example
# start al[Tab]
# start alsa
#:: Saving ALSA Levels [DONE]
#:: Restoring ALSA Levels [DONE]
# takes the first argument as action,
# the rest is treated as services
function _service_control {
if (( ${#argv} < 2 )) ; then
echo "$0: (start|stop|restart) service1 service2 ..."
return 1
else
local action="$1"
shift
for arg in "${*[@]}"; do
sudo /etc/(rc.d|init.d)/$arg $action
done
fi
}
function _gen_service_functions {
local -a actions
# To implement more functions just extend this array
actions=( start stop restart )
foreach action ($actions[@]) do
function $action() {
_service_control $action $@
}
done
local rc_files
# get all rc files as basename
rc_files=`echo /etc/(rc.d|init.d)/*(.:t)`
# register the completion function
compctl -k "($rc_files)" $actions[@]
}
_gen_service_functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment