Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Last active February 14, 2016 04:24
Show Gist options
  • Save ttscoff/e44bb3eff0c87bf8ae78 to your computer and use it in GitHub Desktop.
Save ttscoff/e44bb3eff0c87bf8ae78 to your computer and use it in GitHub Desktop.
#!/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