Last active
December 24, 2015 15:19
-
-
Save apchamberlain/6819201 to your computer and use it in GitHub Desktop.
bash completion for 'service' command on Linux
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
# Add bash completion for services: it tries to complete the service you want | |
# based on the output of "service --status-all" | |
# Source this as a separate file from your .bash_profile or just copy and paste into it | |
# Inspired by http://en.newinstance.it/2011/06/30/ssh-bash-completion/ | |
__service_known_services() { | |
service --status-all |awk '{print $1}' | |
} | |
_service() { | |
local cur known_services | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
known_services="$(__service_known_services)" | |
if [[ ! ${cur} == -* ]] ; then | |
COMPREPLY=( $(compgen -W "${known_services}" -- ${cur}) ) | |
return 0 | |
fi | |
} | |
complete -o bashdefault -o default -o nospace -F _service service 2>/dev/null \ | |
|| complete -o default -o nospace -F _service service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment