From 4fdd247db6af6177a1ac66eaa4a01c1541e7b69a Mon Sep 17 00:00:00 2001 From: John Southworth Date: Mon, 17 Oct 2011 15:15:40 -0500 Subject: Allow completions using normal dirctory paths as well as a shortcut to running:// in file name completions --- functions/interpreter/vyatta-image-complete | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'functions') diff --git a/functions/interpreter/vyatta-image-complete b/functions/interpreter/vyatta-image-complete index d9dc240..130fa13 100644 --- a/functions/interpreter/vyatta-image-complete +++ b/functions/interpreter/vyatta-image-complete @@ -21,13 +21,17 @@ _vyatta_image_is_file() { local cur=$1 - cur=${cur/:/} - topdir=${cur%%/*} - cur=${cur#$topdir/} + if ! [[ ${cur:0:1} =~ "/" ]]; then + cur=${cur/:/} + topdir=${cur%%/*} + cur=${cur#$topdir/} + fi if [[ $topdir == "running" ]]; then cur="/${cur}" elif [[ $topdir == "disk-install" ]]; then cur="/live/image/${cur}" + elif [[ ${cur:0:1} =~ "/" ]]; then + cur=${cur} else cur="/live/image/boot/${topdir}/live-rw/${cur}" fi @@ -57,6 +61,14 @@ _vyatta_image_path_complete() _vyatta_op_completions=( "${cur} " ) return 0; fi + if [[ ${cur:0:1} =~ "/" ]]; then + reply=( $(compgen -f ${cur}) ) + for ((i=0; i < ${#reply[@]}; i++)); do + [[ -d ${reply[i]} ]] && reply[i]="${reply[i]}"/ + done + _vyatta_op_completions=( "${reply[@]}" ) + return + fi if [[ ${cur} == "" ]]; then reply=( $(compgen -d /live/image/boot/ | grep -v grub) ) for i in `seq 0 $[${#reply[@]}-1]`; do @@ -85,7 +97,7 @@ _vyatta_image_path_complete() else cur="/live/image/boot/${cur}" fi - reply=( $(compgen -f ${cur}) ) + reply=( $(compgen -f ${cur} | grep -v grub) ) for i in `seq 0 $[${#reply[@]}-1]`; do file=${reply[$i]} if [[ $isrunningimg == "running" ]];then @@ -129,7 +141,7 @@ _vyatta_image_path_complete() if [[ $topdir == "running" ]]; then reply[$i]=${file/#\//"$topdir://"} elif [[ $topdir == "disk-install" ]]; then - reply[$i]=${file/#\/live\/image\//$"$topdir://"} + reply[$i]=${file/#\/live\/image\//"$topdir://"} else reply[$i]=${file/#\/live\/image\/boot\/$topdir/"$topdir://"} reply[$i]=${reply[$i]/\/live-rw\/} -- cgit v1.2.3