aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2024-03-14 16:02:50 -0700
committerKaz Kylheku <kaz@kylheku.com>2024-03-14 16:02:50 -0700
commitacaae64ab3bf58d7042efb907d15fa359e70a831 (patch)
tree1a7185d0f3d9bd532b6b44bd426cb97f61b7db63
parente306be78a574f324af674db992e8a6b26bf32a5d (diff)
downloadcdlog-acaae64ab3bf58d7042efb907d15fa359e70a831.tar.gz
cdlog-acaae64ab3bf58d7042efb907d15fa359e70a831.tar.bz2
cdlog-acaae64ab3bf58d7042efb907d15fa359e70a831.zip
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.
-rw-r--r--README.md6
-rw-r--r--cdlog.sh6
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