aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2024-04-10 21:20:13 -0700
committerKaz Kylheku <kaz@kylheku.com>2024-04-10 21:20:13 -0700
commit83bf01f9e0b69c55bf151867551147feef6ddc07 (patch)
tree072ff29e0b14963ff834e39a345b111aa18e0455
parentc068e59e179c92b2a7b27e5dbf737ef767e340b9 (diff)
downloadcdlog-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.md8
-rw-r--r--cdlog.sh21
2 files changed, 29 insertions, 0 deletions
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