diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-02-13 07:16:46 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-02-13 07:16:46 -0800 |
commit | 54abe4cd5eba749f3150fa77c9845bedde8fddf1 (patch) | |
tree | ab76ae85b3666816253e1e556c4383a40faee58f | |
parent | 94be3faf70adf727be17bae416d6a13217097b86 (diff) | |
download | cdlog-54abe4cd5eba749f3150fa77c9845bedde8fddf1.tar.gz cdlog-54abe4cd5eba749f3150fa77c9845bedde8fddf1.tar.bz2 cdlog-54abe4cd5eba749f3150fa77c9845bedde8fddf1.zip |
Split off recovery from initialization.
Prompting the user on startup can be a nuisance. For instance,
each time I make a new shell out of a text editor, I get
the prompt. Let's just leave the user in a new context, and
make it an explicit command to switch context.
* cdlog.sh (cdlog.init): Remove logic for selecting a new
context, leaving only the allocation of a new context.
(cdlog.recover): New function, split off from cdlog.init.
(cdr): New alias.
* README.md: Documented.
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | cdlog.sh | 23 |
2 files changed, 24 insertions, 8 deletions
@@ -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? @@ -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 |