aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2015-12-15 17:26:33 +1300
committerTom Ryder <tom@sanctum.geek.nz>2015-12-15 17:26:33 +1300
commitcdf10cb02ed616d922ef7a46c303b5d0e5c869fc (patch)
tree232fc24868e20806deb72ccbb9bbe9f92613d087 /bash
parentConsistent usage output (diff)
downloaddotfiles-cdf10cb02ed616d922ef7a46c303b5d0e5c869fc.tar.gz
dotfiles-cdf10cb02ed616d922ef7a46c303b5d0e5c869fc.zip
Flatten _path completion spec a bit
Diffstat (limited to 'bash')
-rw-r--r--bash/bashrc.d/path.bash105
1 files changed, 51 insertions, 54 deletions
diff --git a/bash/bashrc.d/path.bash b/bash/bashrc.d/path.bash
index f6a9c5b0..d2bf6d37 100644
--- a/bash/bashrc.d/path.bash
+++ b/bash/bashrc.d/path.bash
@@ -181,63 +181,60 @@ EOF
_path() {
# What to do depends on which word we're completing
- case $COMP_CWORD in
+ if ((COMP_CWORD == 1)) ; then
# Complete operation as first word
- 1)
- local cmd
- for cmd in help list insert append remove set check ; do
- [[ $cmd == "${COMP_WORDS[COMP_CWORD]}"* ]] || continue
- COMPREPLY[${#COMPREPLY[@]}]=$cmd
- done
- ;;
+ local cmd
+ for cmd in help list insert append remove set check ; do
+ [[ $cmd == "${COMP_WORDS[COMP_CWORD]}"* ]] || continue
+ COMPREPLY[${#COMPREPLY[@]}]=$cmd
+ done
- # Complete with either directories or $PATH entries as all other words
- *)
- case ${COMP_WORDS[1]} in
-
- # Complete with a directory
- insert|i|append|add|a|check|c|set|s)
- local dirname
- while IFS= read -d '' -r dirname ; do
- COMPREPLY[${#COMPREPLY[@]}]=$dirname
- done < <(
-
- # Set options to glob correctly
- shopt -s dotglob nullglob
-
- # Collect directory names, strip trailing slash
- local -a dirnames
- dirnames=("${COMP_WORDS[COMP_CWORD]}"*/)
- dirnames=("${dirnames[@]%/}")
-
- # Bail if no results to prevent empty output
- ((${#dirnames[@]})) || exit 1
-
- # Print results, quoted and null-delimited
- printf '%q\0' "${dirnames[@]}"
- )
- ;;
-
- # Complete with directories from PATH
- remove|rm|r)
- local -a promptarr
- IFS=: read -d '' -a promptarr < <(printf '%s\0' "$PATH")
- local part
- for part in "${promptarr[@]}" ; do
- [[ $part == "${COMP_WORDS[COMP_CWORD]}"* ]] \
- || continue
- COMPREPLY[${#COMPREPLY[@]}]=$(printf '%q\0' "$part")
- done
- ;;
-
- # No completion
- *)
- return 1
- ;;
- esac
- ;;
- esac
+ # Complete with either directories or $PATH entries as all other words
+ else
+ case ${COMP_WORDS[1]} in
+
+ # Complete with a directory
+ insert|i|append|add|a|check|c|set|s)
+ local dirname
+ while IFS= read -d '' -r dirname ; do
+ COMPREPLY[${#COMPREPLY[@]}]=$dirname
+ done < <(
+
+ # Set options to glob correctly
+ shopt -s dotglob nullglob
+
+ # Collect directory names, strip trailing slash
+ local -a dirnames
+ dirnames=("${COMP_WORDS[COMP_CWORD]}"*/)
+ dirnames=("${dirnames[@]%/}")
+
+ # Bail if no results to prevent empty output
+ ((${#dirnames[@]})) || exit 1
+
+ # Print results, quoted and null-delimited
+ printf '%q\0' "${dirnames[@]}"
+ )
+ ;;
+
+ # Complete with directories from PATH
+ remove|rm|r)
+ local -a promptarr
+ IFS=: read -d '' -a promptarr < <(printf '%s\0' "$PATH")
+ local part
+ for part in "${promptarr[@]}" ; do
+ [[ $part == "${COMP_WORDS[COMP_CWORD]}"* ]] \
+ || continue
+ COMPREPLY[${#COMPREPLY[@]}]=$(printf '%q\0' "$part")
+ done
+ ;;
+
+ # No completion
+ *)
+ return 1
+ ;;
+ esac
+ fi
}
complete -F _path path