From f0812b4f1a8e987faccf85ac309a8b7c024f791c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 21 Oct 2015 14:28:49 +1300 Subject: Exclude stuff not a filename in current directory Otherwise Bash adds a slash to it. %q quoting isn't perfect, but it's better --- bash/bashrc.d/bd.bash | 4 ++-- bash/bashrc.d/mysql.bash | 4 ++-- bash/bashrc.d/sd.bash | 14 +++++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) (limited to 'bash') diff --git a/bash/bashrc.d/bd.bash b/bash/bashrc.d/bd.bash index bfef89f2..bc474901 100644 --- a/bash/bashrc.d/bd.bash +++ b/bash/bashrc.d/bd.bash @@ -95,8 +95,8 @@ _bd() { local dirname for dirname in "${dirnames[@]}" ; do [[ $dirname == "${COMP_WORDS[COMP_CWORD]}"* ]] || continue - COMPREPLY=("${COMPREPLY[@]}" "$dirname") + COMPREPLY=("${COMPREPLY[@]}" "$(printf %q "$dirname")") done } -complete -F _bd -o filenames bd +complete -F _bd bd diff --git a/bash/bashrc.d/mysql.bash b/bash/bashrc.d/mysql.bash index 2faa4e81..9efe3795 100644 --- a/bash/bashrc.d/mysql.bash +++ b/bash/bashrc.d/mysql.bash @@ -51,8 +51,8 @@ _mysql() { ((${#cnfs[@]})) || exit 1 # Print the conf names, null-delimited - printf '%s\0' "${cnfs[@]}" + printf '%q\0' "${cnfs[@]}" ) } -complete -F _mysql -o default -o filenames mysql +complete -F _mysql -o default mysql diff --git a/bash/bashrc.d/sd.bash b/bash/bashrc.d/sd.bash index d127321e..75f220d8 100644 --- a/bash/bashrc.d/sd.bash +++ b/bash/bashrc.d/sd.bash @@ -133,12 +133,20 @@ _sd() { dirnames=("${dirnames[@]#../}") dirnames=("${dirnames[@]%/}") + # Iterate again, but exclude the current directory this time + local -a sibs + local dirname + for dirname in "${dirnames[@]}" ; do + [[ $dirname != "${PWD##*/}" ]] || continue + sibs=("${sibs[@]}" "$dirname") + done + # Bail if no results to prevent empty output - ((${#dirnames[@]})) || exit 1 + ((${#sibs[@]})) || exit 1 # Print results, null-delimited - printf '%s\0' "${dirnames[@]}" + printf '%q\0' "${sibs[@]}" ) } -complete -F _sd -o filenames sd +complete -F _sd sd -- cgit v1.2.3