From 83bf01f9e0b69c55bf151867551147feef6ddc07 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 10 Apr 2024 21:20:13 -0700 Subject: Add c command for lookup. * cdlog.sh (cdlog.lookup): new function. (c): New alias. * README.md: Documented. --- README.md | 8 ++++++++ cdlog.sh | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/README.md b/README.md index 2a0fdc3..7e1909a 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/cdlog.sh b/cdlog.sh index 869f708..f1cd6d7 100644 --- a/cdlog.sh +++ b/cdlog.sh @@ -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 -- cgit v1.2.3