aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md9
-rw-r--r--cdlog.sh23
2 files changed, 24 insertions, 8 deletions
diff --git a/README.md b/README.md
index 53d26c8..c6bf5d8 100644
--- a/README.md
+++ b/README.md
@@ -45,6 +45,11 @@ pick which directory to change to or swap with. The terminal cursor is then
retraced back to the top of the menu, and the screen is erased from
that point to the bottom.
+* The `cdr` command is used for recovering previous sessions. It
+presents you with a numbered list of these sessions. You can recover to one of
+the sessions, use a `c` prefix on the number to clone the session into
+the current session, or press Enter to do nothing.
+
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.
@@ -64,8 +69,8 @@ session store being full, it erases the one with the oldest time
stamp and chooses its index.
When one or more persisted session are present, `cdlog`'s initialization
-presents you with a numbered list of these sessions. You can recover to one of
-the sessions or press Enter to go with the newly allocated one.
+mentions this, suggesting that the `cdr` command may be used to recover
+to one of the sessions.
## How is this better?
diff --git a/cdlog.sh b/cdlog.sh
index 99c3338..5db4ad7 100644
--- a/cdlog.sh
+++ b/cdlog.sh
@@ -42,15 +42,13 @@ cdlog.get_param()
fi
}
-# Read state from ~/.cdlog.dirs
+# Initialize state, allocating new ~/.cdlog.N.dirs storage,
+# with LRU replacement.
cdlog.init()
{
- local -a d
- local dir
local i
local oldest
local context
- local sel
c9=; c8=; c7=
c6=; c5=; c4=
@@ -77,10 +75,22 @@ cdlog.init()
fi
cdlog_dirs=~/.cdlog.$context.dirs
-
rm -f $cdlog_dirs
set -- ~/.cdlog.*.dirs
+ if [ $# -gt 0 -a $1 != ~/.cdlog.'*'.dirs ] ; then
+ printf "Use 'cdr' or 'cdlog.recover' to switch to prior cdlog context.\n"
+ fi
+}
+
+cdlog.recover()
+{
+ local -a d
+ local dir
+ local i
+ local sel
+
+ set -- ~/.cdlog.*.dirs
if [ $# -gt 0 -a $1 != ~/.cdlog.'*'.dirs ] ; then
printf "These cdlog contexts exist:\n"
@@ -96,7 +106,7 @@ cdlog.init()
else
printf "Use 1-%s to select context, c1-c%s to clone,\n" $i $i
fi
- printf "or Enter for new blank ontext: "
+ printf "or Enter to keep current context: "
read sel
case $sel in
( [1-9] )
@@ -282,6 +292,7 @@ alias cl='cdlog'
alias cll='cdlog -l'
alias mcd='cdlog.mcd'
alias mcs='cdlog.mcd -s'
+alias cdr='cdlog.recover'
# Better completion for $x[Tab]
shopt -s direxpand