summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Larson <mike@vyatta.com>2011-01-17 16:23:49 -0800
committerMichael Larson <mike@vyatta.com>2011-01-17 16:23:49 -0800
commit9eb6b0a897e246fab4f170fb6b8dccbeb1a0f9ec (patch)
tree1f3f72a73ed63ebe4a3aa7595e7dbf48f4dc8456
parent2dfa548420b05642b070c07b37fc8b01380e5803 (diff)
downloadvyatta-op-9eb6b0a897e246fab4f170fb6b8dccbeb1a0f9ec.tar.gz
vyatta-op-9eb6b0a897e246fab4f170fb6b8dccbeb1a0f9ec.zip
fix for bug 6476.
-rw-r--r--Makefile.am1
-rw-r--r--etc/bash_completion.d/vyatta-op64
-rw-r--r--etc/bash_completion.d/vyatta-op-run87
3 files changed, 90 insertions, 62 deletions
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: