diff options
Diffstat (limited to 'bash/bash_completion.d/sd.bash')
-rw-r--r-- | bash/bash_completion.d/sd.bash | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/bash/bash_completion.d/sd.bash b/bash/bash_completion.d/sd.bash index a776fbe3..4dc72f31 100644 --- a/bash/bash_completion.d/sd.bash +++ b/bash/bash_completion.d/sd.bash @@ -15,18 +15,28 @@ _sd() { # Make globs expand appropriately shopt -s dotglob nullglob if _completion_ignore_case ; then - shopt -s nocaseglob + shopt -s nocasematch 2>/dev/null fi # Print matching sibling dirs that are not the current dir - for sibling in ../"$2"*/ ; do - sibling=${sibling%/} - sibling=${sibling#../} - case $sibling in - ("${PWD##*/}") ;; - (*) printf '%q/' "$sibling" ;; - esac + for sib in ../*/ ; do + # Strip leading ../ + sib=${sib#../} + # Strip trailing slash + sib=${sib%/} + # Skip self + [[ $sib != "${PWD##*/}" ]] || continue + # Check the quoted and unquoted word for matching + for match in "$sib" "$(printf '%q' "$sib")" ; do + # Print any match, slash-terminated + case $match in + ("$2"*) + printf '%s/' "$sib" + continue + ;; + esac + done done ) } -complete -F _sd sd +complete -F _sd -o filenames sd |