diff options
author | Tom Grennan <tgrennan@vyatta.com> | 2007-09-19 16:46:52 -0700 |
---|---|---|
committer | Tom Grennan <tgrennan@vyatta.com> | 2007-09-19 16:46:52 -0700 |
commit | 64e83f470a7076b63bd9b76c7b6bb516cbe9bb92 (patch) | |
tree | 0f933979fe20823f5d248d99f73dd831158a7582 /etc | |
parent | e42c51dd83d1f10421174b454e16e51e9da2eb7d (diff) | |
download | vyatta-op-64e83f470a7076b63bd9b76c7b6bb516cbe9bb92.tar.gz vyatta-op-64e83f470a7076b63bd9b76c7b6bb516cbe9bb92.zip |
redo help like config modeupstream
Diffstat (limited to 'etc')
-rw-r--r-- | etc/bash_completion.d/vyatta-op | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/etc/bash_completion.d/vyatta-op b/etc/bash_completion.d/vyatta-op index 23bd294..f26448d 100644 --- a/etc/bash_completion.d/vyatta-op +++ b/etc/bash_completion.d/vyatta-op @@ -135,23 +135,53 @@ _vyatta_op_scan () done } -_vyatta_op_expand () +_vyatta_op_help () { - local cur=${COMP_WORDS[COMP_CWORD]} + local help + local heading="\nPossible completions:" + local nullglob + local -a subnodes + local subdir - if _vyatta_op_scan "${COMP_WORDS[@]}" ; then - COMPREPLY=($( compgen -W "${_vyatta_op_allowed[*]}" -- $cur )) - _vyatta_op_comp_words=( ${COMP_WORDS[@]} ) + if grep -q allowed: $_vyatta_op_node_def ; then + eval help=$( _vyatta_op_get_node_def_field $_vyatta_op_node_def help ) + if [ ${#_vyatta_op_allowed[@]} -ne 0 ] ; then + echo -ne $heading + for a in ${_vyatta_op_allowed[*]} ; do + printf "\n %-12s $help" $a + done + else + false + fi + else + nullglob=$( shopt -p nullglob ) + shopt -s nullglob + subnodes=( ${_vyatta_op_node_def%/node.def}/*/node.def ) + eval $nullglob + if [ ${#subnodes[@]} -ne 0 ] ; then + echo -ne $heading + for n in ${subnodes[@]} ; do + eval help=$( _vyatta_op_get_node_def_field $n help ) + subdir=${n%/node.def} + printf "\n %-12s $help" ${subdir##*/} + done + else + false + fi fi } -_vyatta_op_help () +_vyatta_op_expand () { - local help + local cur=${COMP_WORDS[COMP_CWORD]} - if _vyatta_op_scan ${_vyatta_op_comp_words[@]} ; then - eval help=$( _vyatta_op_get_node_def_field $_vyatta_op_node_def help ) - echo -e "$help" + if _vyatta_op_scan "${COMP_WORDS[@]}" ; then + COMPREPLY=($( compgen -W "${_vyatta_op_allowed[*]}" -- $cur )) + if [ "${COMP_WORDS[*]}" == "${_vyatta_op_comp_words[*]}" ] ; then + _vyatta_op_help && \ + COMPREPLY=($( compgen -W "--" -- $cur )) + fi + _vyatta_op_comp_words=( "${COMP_WORDS[@]}" ) fi } @@ -176,14 +206,12 @@ then for xd in $vyatta_op_templates/* ; do if [ -d $xd ] ; then cmd=${xd##*/} - complete -F _vyatta_op_expand -o nospace $cmd + complete -F _vyatta_op_expand $cmd eval alias $cmd=\'_vyatta_op_run $cmd\' fi done fi -bind -x '"\e?": _vyatta_op_help' - shopt -s histverify eval $_vyatta_extglob unset _vyatta_extglob |