oils-for-unix / oils

Oils is our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!
http://www.oilshell.org/
Other
2.85k stars 159 forks source link

Initialise history from HISTFILE on startup #2083

Open nisbet-hubbard opened 1 month ago

nisbet-hubbard commented 1 month ago

Currently, even after setting osh’s $HISTFILE to a different location (~/.bash_history in our case) through oshrc, invoking history upon entering an osh lists only the commands stored in the old ~/.local/share/oils/osh_history.

At this moment, at least ~/.bash_history remains intact.

If you then invoke history -a, however, osh replaces the commands in ~/.bash_history (ie $HISTFILE) with those in ~/.local/share/oils/osh_history, with the result that now both $HISTFILE and the history list are populated with the same commands from the old ~/.local/share/oils/osh_history.

andychu commented 1 month ago

Hm so you are setting HISTFILE=foo in oshrc, and it's being ignored?

What about HISTFILE=foo osh , so it's in the environment?

This might be an ordering issue ...


also bash does some weird stuff like calling libc functions when you do LANG=C, I'm not sure if it does something similar when doing HISTFILE=foo, like readline.set_history_file('foo') or something

nisbet-hubbard commented 1 month ago

Yes, I can confirm HISTFILE=foo is in the environment. The problem isn’t foo’s being ignored, but that it’s being tampered with using ~/.local/share/oils/osh_history.

So, osh overwrites foo with whatever is in ~/.local/share/oils/osh_history whenever I exit osh.

andychu commented 4 weeks ago

Hm OK I want to try to repro this ...

andychu commented 3 weeks ago

I can't reproduce this


HISTFILE=~/.bash_history osh

osh$  history   # now it loads the history from that file

This needs a better repro

in both bash and OSH -- describe the steps, and then describe where OSH differs

andychu commented 3 weeks ago

After I exit OSH, and it writes the history file, it seems fine too

nisbet-hubbard commented 5 days ago

Here’s the relevant steps. I was doing

HISTFILE=~/.bash_history osh

osh$  history -a

whereas you were doing

HISTFILE=~/.bash_history osh

osh$  history

That’s why my .bash_history got clobbered when yours was fine. The key is the following bash behaviour

When the shell starts up, the history is initialized from the file named by the HISTFILE variable (default ~/.bash_history).

This isn’t currently implemented in osh, although one can do it manually like you’ve done above.