From acaae64ab3bf58d7042efb907d15fa359e70a831 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 14 Mar 2024 16:02:50 -0700 Subject: cd: support 1-9 argument, like mcd. * cdlog.sh (cdlog.chdir): Check for the directory argument being a value 1 to 9, and substitue the indicated cdlog_hist entry. * README.md: Document. Also correct reference to cdlog_fifo which should be cdlog_hist. --- README.md | 6 ++++-- cdlog.sh | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8fd46a7..a23697b 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,14 @@ Install the file `cdlog.sh` somewhere, and source it from your The user interface consists of three commands: -* `cd` is now an alias which calls the function `cdlog.chdir`. +* `cd` is an alias which calls the function `cdlog.chdir`. Every time you change directory, it pushes the previous directory -into a history log which is stored in the `cdlog_fifo` array. The log maintains +into a history log which is stored in the `cdlog_hist` array. The log maintains nine entries. The ninth entry is erased. The entries are copied into the variables `c1` through `c9`. The first four entries are also copied into the variables `x`, `y`, `z` and `w` for shorter access. +If the argument of `cd` is a number from 1 to 9, it changes to the +specified `cdlog` history element. * `cs` (cd swap) is an alias for a command which exchanges the current directory with a selected `cslog` entry selected diff --git a/cdlog.sh b/cdlog.sh index 81126bb..503c203 100644 --- a/cdlog.sh +++ b/cdlog.sh @@ -147,11 +147,15 @@ cdlog.chdir() { local cur=$PWD local def + declare -n d=cdlog_hist if [ $# -eq 2 -a "$1" = -P ] ; then case $2 in ( */* ) ;; + ( [1-9] ) + set -- -P "${d[$2]}" + ;; ( ?* ) def=${cdlog_alias[$2]} if [ -n "$def" ] ; then @@ -168,8 +172,6 @@ cdlog.chdir() # only if we successfully change to a different # directory do the following - declare -n d=cdlog_hist - if [ $cdlog_lru ] ; then local nx= local pv=$cur -- cgit v1.2.3