Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
bash completion for 'service' command on Linux
# 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
__service_known_services() {
service --status-all |awk '{print $1}'
_service() {
local cur known_services
if [[ ! ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${known_services}" -- ${cur}) )
return 0
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
You can’t perform that action at this time.