From 82bdc9e8ce75c44979701ef052f038e2a9a4448e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 8 Feb 2024 17:49:53 -0800 Subject: Implement multiple persisted sessions. * cdlog.sh (cdlog.update): Name of file is now in $cdlog_dirs. (cdlog.get_param): New function. (cdlog.init): Implement the LRU session selection and optional recovery. The variable $cdlog_dirs is established, pointing to the selected session file. (mainline): Run cdlog.init if $cdlog_dirs is empty. * README.md: Documented. --- README.md | 16 +++++++++----- cdlog.sh | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index db9a0a1..53d26c8 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,17 @@ same directory you are already in. There is no effect on the FIFO. ## Persistence Whenever the nine-element FIFO changes, the current directory and the -contents of the FIFO are written to the file `~/.cslog.dirs`, -one path per line. When `cdlog` initializes, it reads the contents of that -file. It changes to the directory indicated in the first line, and -stuffs the remaining nine lines into the FIFO, thereby recovering -your session. +contents of the FIFO are written to the file `~/.cslog.N.dirs`, +one path per line, where `N` is an internal session number. + +When `cdlog` initializes, it allocates a session by finding a free +value `N` in the range 1 to 10. If it cannot find one due to the +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. ## How is this better? diff --git a/cdlog.sh b/cdlog.sh index ea585ad..32c65de 100644 --- a/cdlog.sh +++ b/cdlog.sh @@ -10,7 +10,7 @@ cdlog.update() w=$c4 # Persist to disk. - cat > ~/.cdlog.dirs < "$cdlog_dirs" <