diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-06-05 23:08:06 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-06-05 23:08:06 +1200 |
commit | e2307ee1116f4d1164587bd78f58d143e4bbb397 (patch) | |
tree | 3b45097fef5b22ba087f965a5e88794767735d26 /bash/bashrc.d/path.bash | |
parent | Don't print empty line for empty PATH (diff) | |
download | dotfiles-e2307ee1116f4d1164587bd78f58d143e4bbb397.tar.gz dotfiles-e2307ee1116f4d1164587bd78f58d143e4bbb397.zip |
Thorough completion for path
Diffstat (limited to 'bash/bashrc.d/path.bash')
-rw-r--r-- | bash/bashrc.d/path.bash | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/bash/bashrc.d/path.bash b/bash/bashrc.d/path.bash index 9ecf1e9a..4e417d32 100644 --- a/bash/bashrc.d/path.bash +++ b/bash/bashrc.d/path.bash @@ -166,5 +166,49 @@ path() { ;; esac } -complete -W 'help list insert append remove set check' path + +# Completion for path +_path() { + local word=${COMP_WORDS[COMP_CWORD]} + + # Complete operation as first word + if ((COMP_CWORD == 1)) ; then + COMPREPLY=( $(compgen -W \ + 'help list insert append remove set check' \ + -- "$word") ) + else + case ${COMP_WORDS[1]} in + + # Complete with one directory + insert|i|append|a|check|c) + if ((COMP_CWORD == 2)) ; then + COMPREPLY=( $(compgen -A directory -- "$word") ) + fi + ;; + + # Complete with any number of directories + set|s) + COMPREPLY=( $(compgen -A directory -- "$word") ) + ;; + + # Complete with directories from PATH + remove|rm|r) + local -a promptarr + IFS=: read -a promptarr < <(printf '%s\n' "$PATH") + local part + for part in "${promptarr[@]}" ; do + if [[ $part && $part == "$word"* ]] ; then + COMPREPLY=("${COMPREPLY[@]}" "$part") + fi + done + ;; + + # No completion + *) + return 1 + ;; + esac + fi +} +complete -F _path path |