diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-03-14 16:02:50 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-03-14 16:02:50 -0700 |
commit | acaae64ab3bf58d7042efb907d15fa359e70a831 (patch) | |
tree | 1a7185d0f3d9bd532b6b44bd426cb97f61b7db63 | |
parent | e306be78a574f324af674db992e8a6b26bf32a5d (diff) | |
download | cdlog-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.md | 6 | ||||
-rw-r--r-- | cdlog.sh | 6 |
2 files changed, 8 insertions, 4 deletions
@@ -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 @@ -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 |