On 09.02.2024 01:17, Kaz Kylheku wrote:
> On 2024-02-08, Janis Papanagnou <
janis_pap...@hotmail.com> wrote:
>> On 08.02.2024 22:21, Kaz Kylheku wrote:
>>>
>>> - peristence: whenever the state changes, the current working
>>> directory and the 9 element FIFO are saved to ~/.cdlog.dirs.
>>> On startup, this state is recovered.
>>
>> Is it possible to have or define individual .cdlog.dirs files?
>
> Well, yes; just a good set of requirement have to be identified
> for that.
Yes, there's various behaviors that people might expects. Below
are mine described. (It's coupled to the tty device number, as
I've similarly set up my shell history files to depend on the tty
number. - Other folks may certainly have differing requirements.)
>
>> (I'm asking because I'm using shell functions to persist the
>> current working directory _for each terminal instance_, so that
>> on reopening of any terminal I am again in the same tty specific
>> working directory context.)
>
> If you just have one session and bail out, and log in on a different
> tty, then what?
In my case I memorize the cd context for each shell with own tty.
That means a new shell instance in the same tty will initially
operate on the same directory. If I close a shell terminal and
then open a new one it gets the same tty device number assigned
and thus the same (previous) working directory for that shell.
I couple the dot-file it with the terminal tty info from tty(1)
On a 'cd' I do pwd > "${HOME}/.sh_pwdstat_${TTYNR}" that gets
reloaded when a new shell is initialized. (There's a rare hangup
case I've observed that a shell plus its window gets closed but
the tty is still connected to the closed (zombie?) shell; here I
have to identify and kill the invisible shell process explicitly
so that the device number can be reassigned). But normally the
previous context is available (as desired by me) in the reopened
shell.
>
> One way is to have recovery workflow. Show the user what saved contexts
> exist, including the date when they were saved, and let them pick the
> one to use.
This is a grade of flexibility that is (for me) unnecessary (it
may be even a burden to see a menu). I'm not (not yet) using a
cd stack. But if so I'd certainly also couple it (like history
and the last working cd path) also to the tty; I'd probably just
extend my .sh_pwdstat_${TTYNR} to carry the stack of paths like
you've done in your .cdlog.dirs file.
>
> These contexts could be in some LRU list, so they don't proliferate.
> If there are eight, the oldest one is deleted.
>
Janis