aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-12-02 23:10:23 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-12-02 23:10:23 +1300
commitf7b14abebc09ac9720c259c26b91b0640d2555a0 (patch)
tree8458d8d90eec9c3b58ea23fa2f373b20ca9eebb7 /bash
parenta047504ab46f7fcf84a0425a802ad34310ad021c (diff)
downloaddotfiles-f7b14abebc09ac9720c259c26b91b0640d2555a0.tar.gz
dotfiles-f7b14abebc09ac9720c259c26b91b0640d2555a0.zip
Make bd() and sd() match quoted and unquoted words
I suspect there's a more correct way to do this, but it's working well for the moment.
Diffstat (limited to 'bash')
-rw-r--r--bash/bash_completion.d/bd.bash16
-rw-r--r--bash/bash_completion.d/sd.bash28
2 files changed, 31 insertions, 13 deletions
diff --git a/bash/bash_completion.d/bd.bash b/bash/bash_completion.d/bd.bash
index 4dde0eac..32969522 100644
--- a/bash/bash_completion.d/bd.bash
+++ b/bash/bash_completion.d/bd.bash
@@ -36,10 +36,18 @@ _bd() {
# Iterate through the nodes and print the ones that match the word
# being completed, with a trailing slash as terminator
for node in "${nodes[@]}" ; do
- case $node in
- ("$2"*) printf '%s/' "$node" ;;
- esac
+ node_quoted=$(printf '%q' "$node")
+ # Check the quoted and unquoted word for matching
+ for match in "$node" "$(printf '%q' "$node")" ; do
+ # Print any match, slash-terminated
+ case $match in
+ ("$2"*)
+ printf '%s/' "$node"
+ continue
+ ;;
+ esac
+ done
done
)
}
-complete -F _bd bd
+complete -F _bd -o filenames bd
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