Created
November 14, 2013 17:31
-
-
Save relistan/7470868 to your computer and use it in GitHub Desktop.
Upstart bash auto-completion that works on RHEL/CentOS with older versions of Upstart.
This file contains 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
# bash-completion for the upstart event-based init replacement | |
# (http://upstart.ubuntu.com / https://launchpad.net/upstart) | |
# | |
# We don't provide completion for 'init' itself for obvious reasons. | |
# Original is from: https://bugs.launchpad.net/ubuntu/+source/upstart/+bug/672067/+attachment/1765103/+files/upstart.sh | |
_upstart_conf_events() | |
{ | |
initctl list|awk '{print $1}' | |
} | |
_upstart_named_events() | |
{ | |
(cd /etc/init && grep '^emits ' *.conf|sed 's/^emits //g') | |
} | |
_upstart_events() | |
{ | |
(_upstart_conf_events;_upstart_named_events)|tr ' ' '\n'|sort -u | |
} | |
_upstart_startable_events() | |
{ | |
initctl list|cut -d\, -f1|awk '$2 == "stop/waiting" {print $1}' | |
} | |
_upstart_stoppable_events() | |
{ | |
initctl list|cut -d\, -f1|awk '$2 == "start/running" {print $1}' | |
} | |
_upstart_initctl() | |
{ | |
_get_comp_words_by_ref cur prev | |
COMPREPLY=() | |
case "$prev" in | |
start) | |
COMPREPLY=( $(compgen -W "-n --no-wait $(_upstart_startable_events)" -- ${cur}) ) | |
return 0 | |
;; | |
stop) | |
COMPREPLY=( $(compgen -W "-n --no-wait $(_upstart_stoppable_events)" -- ${cur}) ) | |
return 0 | |
;; | |
emit) | |
COMPREPLY=( $(compgen -W "$(_upstart_events)" -- ${cur}) ) | |
return 0 | |
;; | |
reload|restart|status) | |
COMPREPLY=( $(compgen -W "$(_upstart_conf_events)" -- ${cur}) ) | |
return 0 | |
;; | |
-n|--no-wait) | |
# allow no wait after start/stop commands | |
for cmd in start stop | |
do | |
cwords=${COMP_WORDS[@]##} | |
filtered_cwords=${COMP_WORDS[@]##${cmd}} | |
if [ "$filtered_cwords" != "$cwords" ] | |
then | |
COMPREPLY=( $(compgen -W "$(_upstart_${cmd}able_events)" -- ${cur}) ) | |
return 0 | |
fi | |
done | |
;; | |
--help|--version) | |
COMPREPLY=() | |
return 0 | |
;; | |
esac | |
opts="--help --version -q --quiet -v --verbose --system --dest=" | |
cmds=$(initctl help|grep "^ [^ ]"|awk '{print $1}') | |
COMPREPLY=( $(compgen -W "${opts} ${cmds}" -- ${cur}) ) | |
} && complete -F _upstart_initctl initctl | |
_upstart_start() | |
{ | |
COMPREPLY=() | |
_get_comp_words_by_ref cur prev | |
opts="--help --version -q --quiet -v --verbose --system --dest= \ | |
-n --no-wait" | |
case "$prev" in | |
--help|--version) | |
COMPREPLY=() | |
return 0 | |
;; | |
esac | |
COMPREPLY=( $(compgen -W "$opts $(_upstart_startable_events)" -- ${cur}) ) | |
return 0 | |
} && complete -F _upstart_start start | |
_upstart_stop() | |
{ | |
COMPREPLY=() | |
_get_comp_words_by_ref cur prev | |
opts="--help --version -q --quiet -v --verbose --system --dest= \ | |
-n --no-wait" | |
case "$prev" in | |
--help|--version) | |
COMPREPLY=() | |
return 0 | |
;; | |
esac | |
COMPREPLY=( $(compgen -W "$opts $(_upstart_stoppable_events)" -- ${cur}) ) | |
return 0 | |
} && complete -F _upstart_stop stop | |
_upstart_restart() | |
{ | |
COMPREPLY=() | |
_get_comp_words_by_ref cur prev | |
opts="--help --version -q --quiet -v --verbose --system --dest= \ | |
-n --no-wait" | |
case "$prev" in | |
--help|--version) | |
COMPREPLY=() | |
return 0 | |
;; | |
esac | |
COMPREPLY=( $(compgen -W "$opts $(_upstart_events)" -- ${cur}) ) | |
return 0 | |
} && complete -F _upstart_restart restart | |
_upstart_status() | |
{ | |
COMPREPLY=() | |
_get_comp_words_by_ref cur prev | |
opts="--help --version -q --quiet -v --verbose --system --dest=" | |
case "$prev" in | |
--help|--version) | |
COMPREPLY=() | |
return 0 | |
;; | |
esac | |
COMPREPLY=( $(compgen -W "$opts $(_upstart_events)" -- ${cur}) ) | |
return 0 | |
} && complete -F _upstart_status status | |
_upstart_reload() | |
{ | |
COMPREPLY=() | |
_get_comp_words_by_ref cur prev | |
opts="--help --version -q --quiet -v --verbose --system --dest=" | |
case "$prev" in | |
--help|--version) | |
COMPREPLY=() | |
return 0 | |
;; | |
esac | |
COMPREPLY=( $(compgen -W "$opts $(_upstart_events)" -- ${cur}) ) | |
return 0 | |
} && complete -F _upstart_reload reload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment