diff options
Diffstat (limited to 'bash/bash_completion.d/ud.bash')
-rw-r--r-- | bash/bash_completion.d/ud.bash | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/bash/bash_completion.d/ud.bash b/bash/bash_completion.d/ud.bash new file mode 100644 index 00000000..47171b78 --- /dev/null +++ b/bash/bash_completion.d/ud.bash @@ -0,0 +1,28 @@ +# Completion setup for ud +_ud() { + + # Only makes sense for the second argument + ((COMP_CWORD == 2)) || return 1 + + # Iterate through directories, null-separated, add them to completions + local dirname + while IFS= read -rd '' dirname ; do + COMPREPLY[${#COMPREPLY[@]}]=$dirname + done < <( + + # Set options to glob correctly + shopt -s dotglob nullglob + + # Collect directory names, strip trailing slashes + local -a dirnames + dirnames=("${COMP_WORDS[COMP_CWORD]}"*/) + dirnames=("${dirnames[@]%/}") + + # Bail if no results to prevent empty output + ((${#dirnames[@]})) || exit 1 + + # Print results null-delimited + printf '%s\0' "${dirnames[@]}" + ) +} +complete -F _ud -o filenames ud |