From 9eb6b0a897e246fab4f170fb6b8dccbeb1a0f9ec Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Mon, 17 Jan 2011 16:23:49 -0800 Subject: fix for bug 6476. --- Makefile.am | 1 + etc/bash_completion.d/vyatta-op | 64 +-------------------------- etc/bash_completion.d/vyatta-op-run | 87 +++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 62 deletions(-) create mode 100644 etc/bash_completion.d/vyatta-op-run diff --git a/Makefile.am b/Makefile.am index 302f108..7ad4452 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,7 @@ defaultdir = /etc/default default_DATA = etc/default/vyatta completiondir = /etc/bash_completion.d completion_DATA = etc/bash_completion.d/vyatta-op +completion_DATA += etc/bash_completion.d/vyatta-op-run opdir = $(datadir)/vyatta-op/templates bin_sudo_usersdir = $(bindir)/sudo-users diff --git a/etc/bash_completion.d/vyatta-op b/etc/bash_completion.d/vyatta-op index 49b6768..aa516bc 100644 --- a/etc/bash_completion.d/vyatta-op +++ b/etc/bash_completion.d/vyatta-op @@ -66,6 +66,8 @@ declare _vyatta_op_node_path declare -a _vyatta_op_noncompletions _vyatta_op_completions declare -x -a _vyatta_pipe_noncompletions _vyatta_pipe_completions +source /etc/bash_completion.d/vyatta-op-run + # $1: label # #2...: strings _vyatta_op_debug () @@ -108,26 +110,6 @@ _vyatta_op_init () shopt -s histverify } -_vyatta_op_get_node_def_field () -{ - local file=$1 field=$2 - - sed -n '/^'"$field"':/,$ { -# strip field name and hold rest of line - s/[a-z]*: *// - h - :b -# at EOF, print hold buffer and quit - $ { x; p; q } -# input next line - n -# if start of another field def, print hold buf and quit - /^[a-z]*:/ { x; p; q } -# add to hold buf and branch to input next line - H - bb - }' $file -} # $1: label # $2...: help @@ -316,48 +298,6 @@ _vyatta_op_expand () eval "$restore_shopts" } -_vyatta_op_run () -{ - local -i estat - local tpath=$vyatta_op_templates - local restore_shopts=$( shopt -p extglob nullglob | tr \\n \; ) - shopt -s extglob nullglob - - _vyatta_op_last_comp=${_vyatta_op_last_comp_init} - false; estat=$? - - i=1 - for arg in "$@" - do - if [ -f "$tpath/$arg/node.def" ] ; then - tpath+=/$arg - elif [ -f $tpath/node.tag/node.def ] ; then - tpath+=/node.tag - else - echo "Invalid command" >&2 - eval $restore_shopts - return 1 - fi - let "i+=1" - done - - local run_cmd=$(_vyatta_op_get_node_def_field $tpath/node.def run) - local ret=0 - if [ -n "$run_cmd" ]; then - if [[ -t 1 && "$1" == "show" && \ - ! $run_cmd =~ ^\(LESSOPEN=\|less\|pager\|tail\|/opt/vyatta/bin/vyatta-tshark-interface-port.pl\).* ]] ; then - eval "($run_cmd) | ${VYATTA_PAGER:-cat}" - else - eval "$run_cmd" - fi - else - echo "Incomplete command" >&2 - ret=1 - fi - eval $restore_shopts - return $ret -} - # "pipe" functions count () { diff --git a/etc/bash_completion.d/vyatta-op-run b/etc/bash_completion.d/vyatta-op-run new file mode 100644 index 0000000..053dc0e --- /dev/null +++ b/etc/bash_completion.d/vyatta-op-run @@ -0,0 +1,87 @@ + +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2006, 2007 Vyatta, Inc. +# All Rights Reserved. +# +# Author: Tom Grennan +# Date: 2007 +# Description: setup bash completion for Vyatta operational commands +# +# **** End License **** + +_vyatta_op_get_node_def_field () +{ + local file=$1 field=$2 + + sed -n '/^'"$field"':/,$ { +# strip field name and hold rest of line + s/[a-z]*: *// + h + :b +# at EOF, print hold buffer and quit + $ { x; p; q } +# input next line + n +# if start of another field def, print hold buf and quit + /^[a-z]*:/ { x; p; q } +# add to hold buf and branch to input next line + H + bb + }' $file +} + +_vyatta_op_run () +{ + local -i estat + local tpath=$vyatta_op_templates + local restore_shopts=$( shopt -p extglob nullglob | tr \\n \; ) + shopt -s extglob nullglob + + _vyatta_op_last_comp=${_vyatta_op_last_comp_init} + false; estat=$? + + i=1 + for arg in "$@" + do + if [ -f "$tpath/$arg/node.def" ] ; then + tpath+=/$arg + elif [ -f $tpath/node.tag/node.def ] ; then + tpath+=/node.tag + else + echo "Invalid command" >&2 + eval $restore_shopts + return 1 + fi + let "i+=1" + done + + local run_cmd=$(_vyatta_op_get_node_def_field $tpath/node.def run) + local ret=0 + if [ -n "$run_cmd" ]; then + if [[ -t 1 && "$1" == "show" && \ + ! $run_cmd =~ ^\(LESSOPEN=\|less\|pager\|tail\|/opt/vyatta/bin/vyatta-tshark-interface-port.pl\).* ]] ; then + eval "($run_cmd) | ${VYATTA_PAGER:-cat}" + else + eval "$run_cmd" + fi + else + echo "Incomplete command" >&2 + ret=1 + fi + eval $restore_shopts + return $ret +} + +### Local Variables: +### mode: shell-script +### End: -- cgit v1.2.3