diff options
author | John Southworth <john.southworth@vyatta.com> | 2011-09-30 12:37:26 -0500 |
---|---|---|
committer | John Southworth <john.southworth@vyatta.com> | 2011-09-30 12:50:09 -0500 |
commit | 08470d0d254fe5e7346e2d6a8500657856951d37 (patch) | |
tree | dda7f832a75de6748a90908794eeba56db715786 /etc | |
parent | 5e8e22c445eaea3ff0c94cc87be2ece7d8bc5ac7 (diff) | |
download | vyatta-op-08470d0d254fe5e7346e2d6a8500657856951d37.tar.gz vyatta-op-08470d0d254fe5e7346e2d6a8500657856951d37.zip |
Reformat vyatta-op script, there were two indentation styles, changed from tabs to spaces
Diffstat (limited to 'etc')
-rw-r--r-- | etc/bash_completion.d/vyatta-op | 231 |
1 files changed, 115 insertions, 116 deletions
diff --git a/etc/bash_completion.d/vyatta-op b/etc/bash_completion.d/vyatta-op index 21b57d4..7a8206e 100644 --- a/etc/bash_completion.d/vyatta-op +++ b/etc/bash_completion.d/vyatta-op @@ -78,8 +78,6 @@ if [[ "$VYATTA_USER_LEVEL_DIR" != "/opt/vyatta/etc/shell/level/admin" ]]; then _vyatta_operator_allowed=( $(cat $VYATTA_USER_LEVEL_DIR/allowed-op) ) fi -#source /etc/bash_completion.d/vyatta-op-run - declare -a functions functions=( /opt/vyatta/share/vyatta-op/functions/interpreter/* ) @@ -94,7 +92,7 @@ _vyatta_op_debug () echo -ne \\n$1: shift for s ; do - echo -ne " \"$s\"" + echo -ne " \"$s\"" done } @@ -116,15 +114,16 @@ _vyatta_op_default_expand () _vyatta_op_print_help () { local label=$1 help=$2 - - if [ ${#help} -eq 0 ] ; then - echo -ne "\n $label" + if [ ${#label} -eq 0 ] ; then + return + elif [ ${#help} -eq 0 ] ; then + echo -ne "\n $label" elif [ ${#label} -lt 6 ] ; then - echo -ne "\n $label\t\t$help" + echo -ne "\n $label\t\t$help" elif [ ${#label} -lt 14 ] ; then - echo -ne "\n $label\t$help" + echo -ne "\n $label\t$help" else - echo -ne "\n $label\n\t\t$help" + echo -ne "\n $label\n\t\t$help" fi } @@ -137,43 +136,43 @@ _vyatta_op_help () ndef=${_vyatta_op_node_path}/node.tag/node.def [ -f $ndef ] && \ - node_tag_help=$( _vyatta_op_get_node_def_field $ndef help ) + node_tag_help=$( _vyatta_op_get_node_def_field $ndef help ) ndef=${_vyatta_op_node_path}/node.def [ -f $ndef ] && \ - node_run=$( _vyatta_op_get_node_def_field $ndef run ) + node_run=$( _vyatta_op_get_node_def_field $ndef run ) echo -en "\nPossible completions:" if [ -z "$cur" -a -n "$node_run" ]; then - _vyatta_op_print_help '<Enter>' "Execute the current command" + _vyatta_op_print_help '<Enter>' "Execute the current command" fi for comp ; do - if [ -z "$comp" ] ; then - if [ "X$node_tag_help" == "X$last_help" ] ; then - help="" - else - last_help=$node_tag_help - help=$node_tag_help - fi - _vyatta_op_print_help '*' "$help" - elif [[ -z "$cur" || $comp == ${cur}* ]] ; then - ndef=${_vyatta_op_node_path}/$comp/node.def - if [ -f $ndef ] ; then - help=$( _vyatta_op_get_node_def_field $ndef help ) - else - help=$node_tag_help - fi - if [ "X$help" == "X$last_help" ] ; then - help="" - else - last_help=$help - fi - if [[ "$comp" == "<Enter>" ]]; then - continue - else - _vyatta_op_print_help "$comp" "$help" + if [ -z "$comp" ] ; then + if [ "X$node_tag_help" == "X$last_help" ] ; then + help="" + else + last_help=$node_tag_help + help=$node_tag_help + fi + _vyatta_op_print_help '*' "$help" + elif [[ -z "$cur" || $comp == ${cur}* ]] ; then + ndef=${_vyatta_op_node_path}/$comp/node.def + if [ -f $ndef ] ; then + help=$( _vyatta_op_get_node_def_field $ndef help ) + else + help=$node_tag_help + fi + if [ "X$help" == "X$last_help" ] ; then + help="" + else + last_help=$help + fi + if [[ "$comp" == "<Enter>" ]]; then + continue + else + _vyatta_op_print_help "$comp" "$help" + fi fi - fi done } @@ -188,33 +187,34 @@ _vyatta_op_set_node_path () else node=$(_vyatta_op_conv_node_path $_vyatta_op_node_path ${COMP_WORDS[i]}) fi - 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 - return 1 - fi + 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 + return 1 + fi done } _vyatta_op_set_completions () { local -a allowed completions + local cur=$1 for ndef in ${_vyatta_op_node_path}/*/node.def ; do - if [[ $ndef == */node.tag/node.def ]] ; then - local acmd=$( _vyatta_op_get_node_def_field $ndef allowed ) - local -a a=($( eval "$acmd" )) - if [ ${#a[@]} -ne 0 ] ; then - allowed+=( "${a[@]}" ) - else - allowed+=( "" ) - fi - else - local sdir=${ndef%/*} - allowed+=( ${sdir##*/} ) - fi + if [[ $ndef == */node.tag/node.def ]] ; then + local acmd=$( _vyatta_op_get_node_def_field $ndef allowed ) + local -a a=($( eval "$acmd" )) + if [ ${#a[@]} -ne 0 ] ; then + allowed+=( "${a[@]}" ) + else + allowed+=( "" ) + fi + else + local sdir=${ndef%/*} + allowed+=( ${sdir##*/} ) + fi done # donot complete entries like <HOSTNAME> or <A.B.C.D> @@ -226,34 +226,33 @@ _vyatta_op_set_completions () [ -f $ndef ] && \ node_run=$( _vyatta_op_get_node_def_field $ndef run ) if [ -n "$node_run" ]; then - _vyatta_op_noncompletions+=('<Enter>') + _vyatta_op_noncompletions+=('<Enter>') fi for (( i=0 ; i<${#allowed[@]} ; i++ )) ; do - if [[ "${allowed[i]}" == \<*\> ]] ; then - _vyatta_op_noncompletions+=( ${allowed[i]} ) - else - if [[ "$VYATTA_USER_LEVEL_DIR" == "/opt/vyatta/etc/shell/level/admin" ]]; then - completions+=( ${allowed[i]} ) - elif is_elem_of ${allowed[i]} _vyatta_operator_allowed; then - completions+=( ${allowed[i]} ) - elif [[ $_vyatta_op_node_path == $vyatta_op_templates ]];then - continue - else - completions+=( ${allowed[i]} ) + if [[ "${allowed[i]}" == \<*\> ]] ; then + _vyatta_op_noncompletions+=( ${allowed[i]} ) + else + if [[ "$VYATTA_USER_LEVEL_DIR" == "/opt/vyatta/etc/shell/level/admin" ]]; then + completions+=( ${allowed[i]} ) + elif is_elem_of ${allowed[i]} _vyatta_operator_allowed; then + completions+=( ${allowed[i]} ) + elif [[ $_vyatta_op_node_path == $vyatta_op_templates ]];then + continue + else + completions+=( ${allowed[i]} ) + fi fi - fi done # Prefix filter the non empty completions if [ -n "$cur" ]; then _vyatta_op_completions=() - get_prefix_filtered_list "$cur" completions _vyatta_op_completions + get_prefix_filtered_list "$cur" completions _vyatta_op_completions _vyatta_op_completions=($( printf "%s\n" ${_vyatta_op_completions[@]} | sort -u )) - else + else _vyatta_op_completions=($( printf "%s\n" ${completions[@]} | sort -u )) fi - } _vyatta_op_comprely_needs_ambiguity () @@ -329,13 +328,13 @@ _vyatta_op_expand () fi if [ "${COMP_WORDS[*]}" != "$_vyatta_op_last_comp" ] ; then - if ! _vyatta_op_set_node_path ; then - echo -e \\a - _vyatta_op_invalid_completion - COMPREPLY=( "" " " ) - eval "$restore_shopts" - return 1 - fi + if ! _vyatta_op_set_node_path ; then + echo -e \\a + _vyatta_op_invalid_completion + COMPREPLY=( "" " " ) + eval "$restore_shopts" + return 1 + fi _vyatta_set_comptype case $_vyatta_comptype in 'imagefiles') @@ -344,47 +343,47 @@ _vyatta_op_expand () ;; *) _has_comptype=0 - _vyatta_op_set_completions + _vyatta_op_set_completions $cur ;; esac fi if [[ $_has_comptype == 1 ]]; then - COMPREPLY=( "${_vyatta_op_completions[@]}" ) + COMPREPLY=( "${_vyatta_op_completions[@]}" ) else - COMPREPLY=($( compgen -W "${_vyatta_op_completions[*]}" -- $cur )) + COMPREPLY=($( compgen -W "${_vyatta_op_completions[*]}" -- $cur )) fi # if the last command line arg is empty and we have # an empty completion option (meaning wild card), # append a blank(s) to the completion array to force ambiguity if [ -z "$cur" ] ; then - for comp ; do - if [ -z "$comp" ] ; then - if [ ${#COMPREPLY[@]} -eq 0 ] ; then - COMPREPLY+=( " " "" ) - elif _vyatta_op_comprely_needs_ambiguity ; then - COMPREPLY+=( " " ) - fi - fi - done + for comp ; do + if [ -z "$comp" ] ; then + if [ ${#COMPREPLY[@]} -eq 0 ] ; then + COMPREPLYu=( " " "" ) + elif _vyatta_op_comprely_needs_ambiguity ; then + COMPREPLY+=( " " ) + fi + fi + done fi # if there are no completions then handle invalid commands if [ ${#_vyatta_op_noncompletions[@]} -eq 0 ] && [ ${#_vyatta_op_completions[@]} -eq 0 ]; then echo - _vyatta_op_invalid_completion + _vyatta_op_invalid_completion COMPREPLY=( "" " " ) # if there are no completions then always show the non-comps - elif [ "${COMP_WORDS[*]}" == "$_vyatta_op_last_comp" ] || - [ ${#_vyatta_op_completions[@]} -eq 0 ]; then - _vyatta_op_help "$cur" \ - ${_vyatta_op_noncompletions[@]} \ - ${_vyatta_op_completions[@]} \ - | ${VYATTA_PAGER:-cat} - COMPREPLY=( "" " " ) - _vyatta_op_last_comp=${_vyatta_op_last_comp_init} + elif [ "${COMP_WORDS[*]}" == "$_vyatta_op_last_comp" ] || + [ ${#_vyatta_op_completions[@]} -eq 0 ]; then + _vyatta_op_help "$cur" \ + ${_vyatta_op_noncompletions[@]} \ + ${_vyatta_op_completions[@]} \ + | ${VYATTA_PAGER:-cat} + COMPREPLY=( "" " " ) + _vyatta_op_last_comp=${_vyatta_op_last_comp_init} else - _vyatta_op_last_comp="${COMP_WORDS[*]}" + _vyatta_op_last_comp="${COMP_WORDS[*]}" fi eval "$restore_shopts" @@ -485,21 +484,21 @@ _vyatta_set_comptype () { local comptype unset _vyatta_comptype - for ndef in ${_vyatta_op_node_path}/*/node.def ; do - if [[ $ndef == */node.tag/node.def ]] ; then - local comptype=$( _vyatta_op_get_node_def_field $ndef comptype ) - if [[ $comptype == "imagefiles" ]] ; then - _vyatta_comptype=$comptype - return 0 - else - _vyatta_comptype="" - return 1 - fi - else - _vyatta_comptype="" - return 1 - fi - done + for ndef in ${_vyatta_op_node_path}/*/node.def ; do + if [[ $ndef == */node.tag/node.def ]] ; then + local comptype=$( _vyatta_op_get_node_def_field $ndef comptype ) + if [[ $comptype == "imagefiles" ]] ; then + _vyatta_comptype=$comptype + return 0 + else + _vyatta_comptype="" + return 1 + fi + else + _vyatta_comptype="" + return 1 + fi + done } nullglob_save=$( shopt -p nullglob ) |