diff options
Diffstat (limited to 'rtadm.bash_completion')
-rw-r--r-- | rtadm.bash_completion | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/rtadm.bash_completion b/rtadm.bash_completion new file mode 100644 index 0000000..15e3c70 --- /dev/null +++ b/rtadm.bash_completion @@ -0,0 +1,53 @@ +# Bash completion for rtadm + +_rtadm_ra_hosts_disabled() { + awk '/^#DISABLED#/ {print $5}' .ssh/authorized_keys | cut -d- -f3 +} + +_rtadm_ra_hosts_enabled() { + awk '/^[^#].* ra-/ {print $5}' .ssh/authorized_keys | cut -d- -f3 +} + +_rtadm_ra_hosts() { + awk '/ ra-/ {print $5}' .ssh/authorized_keys | cut -d- -f3 +} + +_rtadm() { + local cur commands command hosts + + COMPREPLY=() + cur=`_get_cword` + + commands='create show enable disable disconnect delete' + + if [[ $COMP_CWORD -eq 1 ]] ; then + COMPREPLY=( $( compgen -W "$commands" -- $cur ) ) + return 0 + fi + + + command=${COMP_WORDS[1]} + case "$command" in + create) + # Fixme: some completion here. + : #create [-e] port newname + ;; + show) : # No parameters here + ;; + enable) + hosts=`_rtadm_ra_hosts_disabled` + COMPREPLY=( $( compgen -W "$hosts" -- $cur ) ) + ;; + disable|disconnect) + hosts=`_rtadm_ra_hosts_enabled` + COMPREPLY=( $( compgen -W "$hosts" -- $cur ) ) + ;; + delete) + hosts=`_rtadm_ra_hosts` + COMPREPLY=( $( compgen -W "$hosts" -- $cur ) ) + ;; + esac + return 0 +} + +complete -F _rtadm rtadm |