diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-02-23 12:39:10 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-02-23 12:39:10 -0800 |
commit | 12fc4e20184060d3344b72b047dc31dc44065610 (patch) | |
tree | 5903a2a384fcbdc2639b102d96a0603c421b5799 | |
parent | 8629957d6c727d3db36123dcc5675c4fd661f680 (diff) | |
download | cdlog-12fc4e20184060d3344b72b047dc31dc44065610.tar.gz cdlog-12fc4e20184060d3344b72b047dc31dc44065610.tar.bz2 cdlog-12fc4e20184060d3344b72b047dc31dc44065610.zip |
Add tab completion for cd aliases.
* README.md: Documented.
* cdlog.sh (cdlog.complete): Completion function that
completes on directories, including CDPATH,
as well as cdlog's cd aliases.
(toplevel): Register the completion function.
-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> |