diff options
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | cdlog.sh | 29 |
2 files changed, 35 insertions, 0 deletions
@@ -105,6 +105,12 @@ the FIFO. LRU mode keeps duplicate directories out of the FIFO and while promoting recently used directories toward the top. +## Completion + +`cdlog` provides its own Tab completion for the `cd` command, overriding +the built-in completion. It includes the cd aliases, while completing +on directories, taking into account `CDPATH`. + ## How is this better? * It's not hard-coded C code inside the shell; it consists of a small amount of @@ -337,6 +337,33 @@ cdlog.alias() return 0 } +# Tab completion for cd aliases + +cdlog.complete() +{ + COMPREPLY=() + local cur=${COMP_WORDS[COMP_CWORD]} + local alias + local dir + + COMPREPLY+=( $(compgen -d -- "$cur") ) + + for alias in "${!cdlog_alias[@]}"; do + case "$alias" in + ( "$cur"* ) + COMPREPLY+=( "$alias" ) + ;; + esac + done + + IFS=':' set -- $CDPATH + for dir in "$@"; do + COMPREPLY+=( $(compgen -d -- "$dir/$cur") ) + done + + return 0 +} + # Aliases. alias cd='cdlog.chdir -P' alias pd='cdlog.pop' @@ -359,6 +386,8 @@ if [ -z "$c1" -o -z "$cdlog_dirs" ] ; then cdlog.init fi +# Register completion +complete -F cdlog.complete cd # Copyright 2024 # Kaz Kylheku <kaz@kylheku.com> |