1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
# Wed, 13 Mar 2024 16:47:14 +0100
# bash-completion for update-service
_update-service_services()
{
if [ "$(id -u)" != 0 ] && [ "$(id -u)" -ge '1000' ]; then
username="$(id -u -n)"
SVDLIST=$(ls --color=no /home/$username/.runit/sv/)
else
SVDLIST=$(ls --color=no /etc/sv)
for svd in /usr/share/runit/sv.current/* ; do
svdbase=${svd##*/}
[ ! -d /etc/sv/$svdbase ] && SVDLIST="$SVDLIST $svdbase"
done
fi
echo "$SVDLIST"
}
_update-service_comm()
{
echo "--add enable --remove disable --list --check "
}
_update-services()
{
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $( compgen -W "$(_update-service_comm)" -- "$cur" ) )
elif [ $COMP_CWORD -eq 2 ]; then
if [ "$(id -u)" != 0 ] && [ "$(id -u)" -ge '1000' ] ; then
COMPREPLY=( $( compgen -W "$(_update-service_services)" $cur ) )
else
COMPREPLY=( $( compgen -W "$(_update-service_services)" $cur ) )
_filedir -d
fi
fi
}
complete -F _update-services update-service
|