diff options
author | John Southworth <john.southworth@vyatta.com> | 2011-10-05 19:20:49 -0500 |
---|---|---|
committer | John Southworth <john.southworth@vyatta.com> | 2011-10-05 19:20:49 -0500 |
commit | 50bf81d96f374c6a370289a344ab8e1012ad48a9 (patch) | |
tree | 9922be701bd92e1dee40ff085cc05cba195f7cb7 | |
parent | e6eb65e4ed02a69c6aa32991b164c3cd6fa5bf91 (diff) | |
download | vyatta-cfg-50bf81d96f374c6a370289a344ab8e1012ad48a9.tar.gz vyatta-cfg-50bf81d96f374c6a370289a344ab8e1012ad48a9.zip |
Add comments to document the changes in completion script
-rwxr-xr-x | etc/bash_completion.d/vyatta-cfg | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/etc/bash_completion.d/vyatta-cfg b/etc/bash_completion.d/vyatta-cfg index cc169ae..39fa1df 100755 --- a/etc/bash_completion.d/vyatta-cfg +++ b/etc/bash_completion.d/vyatta-cfg @@ -507,6 +507,8 @@ vyatta_do_complete () cur=${COMP_WORDS[COMP_CWORD]} fi local -a f_comps=() + # Get filtered word list, use the current comp word if current_word is empty + # this only happens at the beginning of the line if [ -z "$current_word" ];then get_prefix_filtered_list "$cur" vyatta_completions f_comps else @@ -518,6 +520,10 @@ vyatta_do_complete () done estr="${estr})" eval "$estr" + # Apply ambiguity to the completion array + # This is needed when we have an empty completion + # and there is only one element of the completion array + # This will maintain consistency with op mode completions if [ -z "$cur" ] || [[ "${COMPREPLY[0]}" =~ "$cur" ]]; then for comp ; do @@ -530,9 +536,14 @@ vyatta_do_complete () fi done fi + # If we didn't need ambiguity and there is only one element + # in the compreply array then its the only available word, + # append a space to finish the completion. if [ ${#COMPREPLY[@]} -eq 1 ]; then COMPREPLY=( "${COMPREPLY[0]} " ) fi + # don't show help text if its the same word + # keeps completions from getting stuck if [ ${#vyatta_completions[@]} -eq 1 ] && [ -n "$cur" ] && [[ "${vyatta_completions[0]}" =~ "$cur" ]]; then @@ -573,6 +584,10 @@ vyatta_simple_complete () COMPREPLY=( "${f_comps[@]}" ) + # Apply ambiguity to the completion array + # This is needed when we have an empty completion + # and there is only one element of the completion array + # This will maintain consistency with op mode completions if [ -z "$current_prefix" ] || [[ "${COMPREPLY[0]}" =~ "$cur" ]]; then for comp ; do @@ -586,6 +601,9 @@ vyatta_simple_complete () done fi + # If we didn't need ambiguity and there is only one element + # in the compreply array then its the only available word, + # append a space to finish the completion. if [[ ${#COMPREPLY[@]} -eq 1 ]]; then COMPREPLY=( "${COMPREPLY[0]} " ) fi @@ -596,6 +614,8 @@ vyatta_simple_complete () echo "f_comps: ${f_comps[@]}" fi + # don't show help text if its the same word + # keeps completions from getting stuck if [ ${#f_comps[@]} -eq 1 ] && [ -n "$cur" ] && [[ "${f_comps[0]}" =~ "$cur" ]]; then @@ -747,7 +767,7 @@ vyatta_config_complete () eval $restore_shopts return fi - + # This handles first word completion if (( ${#COMP_WORDS[@]} < 2 )) || [[ $COMP_CWORD -eq 0 ]]; then _get_help_text_items=( "${_vyatta_cfg_cmds[@]}" ) @@ -755,6 +775,9 @@ vyatta_config_complete () if (( ${#COMP_WORDS[@]} == 1 )); then declare -a fitems=() declare -a fstrs=() + # Get filtered word and help lists + # use the current comp word if current_word is empty + # this only happens at the beginning of the line if [[ -z $current_word ]]; then get_prefix_filtered_list2 "${COMP_WORDS[0]}" \ _get_help_text_items fitems _get_help_text_helps fstrs @@ -843,6 +866,9 @@ vyatta_config_complete () echo -e "Last comp: $last_comp" fi + # Change the api arguments when we are dealing with a non last word + # completion, this allows for completions to work when in the middle + # of a string without requiring the user input additional spaces. if [[ -n "$current_word" ]] && [[ -n "$last_comp" ]] && [[ ! "$current_word" =~ "$last_comp" ]]; then |