Last active
February 20, 2025 09:43
-
-
Save ttscoff/e44bb3eff0c87bf8ae78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Add autocomplete support for bd for bash. | |
_bd() | |
{ | |
OLD_IFS="$IFS" | |
local token=${COMP_WORDS[$COMP_CWORD]} | |
IFS=$'\t' | |
local words=$(pwd | tr / " ") | |
IFS="$OLD_IFS" | |
if [[ "$token" == -* ]]; then | |
COMPREPLY=( $( compgen -W '-s -si' -- $token ) ) | |
else | |
local nocasematchWasOff=0 | |
shopt nocasematch >/dev/null || nocasematchWasOff=1 | |
(( nocasematchWasOff )) && shopt -s nocasematch | |
local w matches=() | |
OLD_IFS="$IFS" | |
IFS=$'\t' | |
for w in $words; do | |
if [[ "$w" == "$token"* ]]; then | |
matches+=("${w// /\ }") | |
fi | |
done | |
IFS="$OLD_IFS" | |
(( nocasematchWasOff )) && shopt -u nocasematch | |
COMPREPLY=("${matches[@]}") | |
fi | |
} | |
complete -F _bd bd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment