diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-04-10 21:20:13 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-04-10 21:20:13 -0700 |
commit | 83bf01f9e0b69c55bf151867551147feef6ddc07 (patch) | |
tree | 072ff29e0b14963ff834e39a345b111aa18e0455 | |
parent | c068e59e179c92b2a7b27e5dbf737ef767e340b9 (diff) | |
download | cdlog-83bf01f9e0b69c55bf151867551147feef6ddc07.tar.gz cdlog-83bf01f9e0b69c55bf151867551147feef6ddc07.tar.bz2 cdlog-83bf01f9e0b69c55bf151867551147feef6ddc07.zip |
Add c command for lookup.
* cdlog.sh (cdlog.lookup): new function.
(c): New alias.
* README.md: Documented.
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | cdlog.sh | 21 |
2 files changed, 29 insertions, 0 deletions
@@ -62,6 +62,14 @@ sessions is possible with a `d` prefix. * The `cdunalias` command removes a cd alias. +* The `c` command takes one argument. If it successfully, resolves to a path, +that path it is printed, and the termination status is successful. Otherwise +nothing is printed and the termination status is failed. If the argument is a +digit in the range 1 to 9, then it resolves to the specified element in the +`cdlog` history, if it is nonblank. If the argument begins with `@`, then it +resolves as a search; see Searches below. Otherwise, it is resolved as a +`cdlog` alias; see Aliases below. + In addition, the `cdlog.sh` script sets the bash `direxpand` option. With the `direxpand` option, Tab completion on a directory coming from a variable name will expand that variable into the command line. @@ -461,6 +461,26 @@ cdlog.unalias() done } +cdlog.lookup() +{ + local out + + case $1 in + ( [1-9] ) + out=${cdlog_hist[$1]} + [ -n "$out" ] && printf "%s\n" "$out" || false + ;; + ( @* ) + cdlog.at2path "$1" + ;; + ( * ) + out=${cdlog_alias[$1]} + [ -n "$out" ] && printf "%s\n" "$out" || false + ;; + esac +} + + # Tab completion for cd aliases cdlog.complete() @@ -502,6 +522,7 @@ alias cdr='cdlog.recover' alias cdalias='cdlog.alias' alias cdaliases='cdlog.aliases' alias cdunalias='cdlog.unalias' +alias c='cdlog.lookup' # Better completion for $x[Tab] shopt -s direxpand |