diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-30 01:17:09 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-30 02:09:30 +1200 |
commit | 4cbbd121c012b3962f12fdff0f1820c3b8636a44 (patch) | |
tree | 00149270df365ed0b7a1b9e9f4922fe7d5a80eb3 /bash/bashrc.d/sd.bash | |
parent | Change ca from Bash func to sh script (diff) | |
download | dotfiles-4cbbd121c012b3962f12fdff0f1820c3b8636a44.tar.gz dotfiles-4cbbd121c012b3962f12fdff0f1820c3b8636a44.zip |
Move bash completion setup into separate dir
Diffstat (limited to 'bash/bashrc.d/sd.bash')
-rw-r--r-- | bash/bashrc.d/sd.bash | 42 |
1 files changed, 1 insertions, 41 deletions
diff --git a/bash/bashrc.d/sd.bash b/bash/bashrc.d/sd.bash index 9d1063d6..ad4a0deb 100644 --- a/bash/bashrc.d/sd.bash +++ b/bash/bashrc.d/sd.bash @@ -30,7 +30,7 @@ # $ pwd # /tmp/tmp.ZSunna5Eup/a # -# Seems to work for symbolic links. Completion included. +# Seems to work for symbolic links. # sd() { @@ -107,43 +107,3 @@ sd() { # Try to change into the determined directory builtin cd "${opts[@]}" ../"$dirname" } - -# Completion function for sd; any sibling directories, excluding the self -_sd() { - - # Only makes sense for the first argument - ((COMP_CWORD == 1)) || return 1 - - # Current directory can't be root directory - [[ $PWD != / ]] || return 1 - - # Build list of matching sibiling directories - while IFS= read -rd '' dirname ; do - COMPREPLY[${#COMPREPLY[@]}]=$dirname - done < <( - - # Set options to glob correctly - shopt -s dotglob nullglob - - # Collect directory names, strip leading ../ and trailing / - local -a dirnames - dirnames=(../"${COMP_WORDS[COMP_CWORD]}"*/) - 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 - ((${#sibs[@]})) || exit 1 - - # Print results, null-delimited - printf '%q\0' "${sibs[@]}" - ) -} -complete -F _sd sd |