summaryrefslogtreecommitdiff
path: root/etc/bash_completion.d/vyatta-op-run
diff options
context:
space:
mode:
Diffstat (limited to 'etc/bash_completion.d/vyatta-op-run')
-rw-r--r--etc/bash_completion.d/vyatta-op-run141
1 files changed, 0 insertions, 141 deletions
diff --git a/etc/bash_completion.d/vyatta-op-run b/etc/bash_completion.d/vyatta-op-run
deleted file mode 100644
index 68c9562..0000000
--- a/etc/bash_completion.d/vyatta-op-run
+++ /dev/null
@@ -1,141 +0,0 @@
-
-# **** 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_conv_node_path ()
-{
- # is the node ok, ambiguous, or invalid
- local node_path
- local node
- local -a ARR
- node_path=$1
- node=$2
- ARR=( "$node_path/$node"* )
- if [[ "${#ARR[@]}" == "1" ]]; then
- echo ${ARR[0]##*/}
- elif [[ "${#ARR[@]}" == "0" ]]; then
- if [[ -d "${node_path}/node.tag" ]]; then
- echo "$node tag"
- else
- echo "$node invalid"
- fi
- elif [[ -d "$node_path/$node" ]]; then
- echo $node
- else
- echo "$node ambiguous"
- fi
-}
-
-_vyatta_op_conv_run_cmd ()
-{
- # Substitue bash positional variables
- # for the same value in the expanded array
- local run_cmd
- run_cmd="$@"
- run_cmd="${run_cmd/\"\$\@\"/${args[*]}}"
- run_cmd="${run_cmd/\$\*/${args[*]}}"
- run_cmd=$(echo -e "$run_cmd" | sed -e 's/\$\([0-9]\)/\$\{args\[\1\]\}/g')
- echo -ne "$run_cmd"
-}
-
-_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
- declare -a args # array of expanded arguments
- for arg in "$@"; do
- arg=( $(_vyatta_op_conv_node_path $tpath $arg) ) # expand the arguments
- # output proper error message based on the above expansion
- if [[ "${arg[1]}" == "ambiguous" ]]; then
- echo -ne "\n Ambiguous command: ${args[@]} [$arg]\n"
- local -a cmds=( "$tpath/$arg"* )
- _vyatta_op_node_path=$tpath
- local comps=$(_vyatta_op_help $arg ${cmds[@]##*/})
- echo -e "$comps\n" | sed -e 's/^P/ P/'
- eval $restore_shopts
- return 1
- elif [[ "${arg[1]}" == "invalid" ]]; then
- echo -ne "\n Invalid command: ${args[@]} [$arg]\n\n"
- eval $restore_shopts
- return 1
- fi
-
- args[$i]=$arg
- 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)
- run_cmd=$(_vyatta_op_conv_run_cmd "$run_cmd") # convert the positional parameters
- local ret=0
- local cmd_regex="^(LESSOPEN=|less|pager|tail|/opt/vyatta/bin/vyatta-tshark-interface-port.pl).*"
- if [ -n "$run_cmd" ]; then
- if [[ -t 1 && "$1" == "show" && ! $run_cmd =~ $cmd_regex ]] ; then
- eval "($run_cmd) | ${VYATTA_PAGER:-cat}"
- else
- eval "$run_cmd"
- fi
- else
- echo -ne "\n Incomplete command: ${args[@]}\n\n" >&2
- ret=1
- fi
- eval $restore_shopts
- return $ret
-}
-
-### Local Variables:
-### mode: shell-script
-### End: