diff options
author | John Southworth <john.southworth@vyatta.com> | 2011-07-29 20:39:22 -0700 |
---|---|---|
committer | John Southworth <john.southworth@vyatta.com> | 2011-07-29 20:39:22 -0700 |
commit | cb6147ccd181a606628089a4222d933ed6145e9c (patch) | |
tree | cd5965019ccdf8725c4acf826d6e1a6861426024 /etc/bash_completion.d/vyatta-op | |
parent | 78f3881862cf4890c0037e59ff4187cde812f716 (diff) | |
download | vyatta-op-cb6147ccd181a606628089a4222d933ed6145e9c.tar.gz vyatta-op-cb6147ccd181a606628089a4222d933ed6145e9c.zip |
Bugfix 2823: Operational mode command interpreter
Diffstat (limited to 'etc/bash_completion.d/vyatta-op')
-rw-r--r-- | etc/bash_completion.d/vyatta-op | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/etc/bash_completion.d/vyatta-op b/etc/bash_completion.d/vyatta-op index 5ac807e..7d6ddb5 100644 --- a/etc/bash_completion.d/vyatta-op +++ b/etc/bash_completion.d/vyatta-op @@ -101,18 +101,23 @@ _vyatta_op_init () complete -E -F _vyatta_op_expand complete -D -F _vyatta_op_default_expand - for xd in $vyatta_op_templates/* ; do - if [ -d $xd ] ; then - cmd=${xd##*/} - complete -F _vyatta_op_expand $cmd - eval alias $cmd=\'_vyatta_op_run $cmd\' - fi + # create the top level aliases for the unambiguous portions of the commands + # this is the only place we need an entire enumerated list of the subcommands + for cmd in $( ls /opt/vyatta/share/vyatta-op/templates/ ); do + for pos in $(seq 1 ${#cmd}); do + case ${cmd:0:$pos} in + for|do|done|if|fi|case|while|tr ) + continue ;; + *) ;; + esac + complete -F _vyatta_op_expand ${cmd:0:$pos} + eval alias ${cmd:0:$pos}=\'_vyatta_op_run ${cmd:0:$pos}\' + done done shopt -s histverify } - # $1: label # $2...: help _vyatta_op_print_help () @@ -177,10 +182,13 @@ _vyatta_op_help () _vyatta_op_set_node_path () { + local node _vyatta_op_node_path=$vyatta_op_templates for (( i=0 ; i<COMP_CWORD ; i++ )) ; do - if [ -f "${_vyatta_op_node_path}/${COMP_WORDS[i]}/node.def" ] ; then - _vyatta_op_node_path+=/${COMP_WORDS[i]} + # expand the command so completion continues to work with short versions + node=$(_vyatta_op_conv_node_path $_vyatta_op_node_path ${COMP_WORDS[i]}) + if [ -f "${_vyatta_op_node_path}/$node/node.def" ] ; then + _vyatta_op_node_path+=/$node elif [ -f ${_vyatta_op_node_path}/node.tag/node.def ] ; then _vyatta_op_node_path+=/node.tag else |