Skip to content

Instantly share code, notes, and snippets.

@WoodenDoors
Created September 22, 2017 07:30
/etc/bash_completion.d/sv
_runit_sv() {
local cur prev commands opts services
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
commands="status up down once \
pause cont hup alarm interrupt quit 1 2 term kill exit \
start stop reload restart shutdown \
force-stop force-reload force-restart force-shutdown try-restart check"
opts="-w -v"
if [ -z "$SVDIR" ]; then
services="$(ls -A /etc/service)"
else
services="$(ls -A "$SVDIR")"
fi
if [[ ${prev} == "sv" ]]; then
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
elif [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
else
COMPREPLY=( $(compgen -W "${services}" -- ${cur}) )
fi
return 0
}
complete -F _runit_sv sv
@robbieh
Copy link

robbieh commented Nov 12, 2017

Excellent, thanks! I forked and added "--color=no" so that color codes don't show up in tab completion.

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