i find it very confusing/disturbing that when i enter a command in one terminal, let's say in ~/project1, and then switch to another terminal which is in ~/project2, and hit cursor-up, to *not* get the last command i entered in that very same terminal, but the one i entered in project1.
i've studied the manual to see whether i can make the behaviour like in bash, but it doesn't seem to be possible at the moment. please consider adding this as a configuration option, because it is annoying to such a degree that i consider to switch back to bash, even though yash is much nicer in many other aspects.
it already happened to me several times that i hit cursor-up-enter as i'm accustomed to to repeat the last command (like e.g. "make") but instead have a completely unrelated command show up (and starting), like youtube-dl something.
i know that bash loses some commands of the history (afaik it writes to .bash_history whenever the bash session is closed from the point where the history file was when that shell was started), but that's not really an issue for me.
the optimal behaviour in my opinion would be that yash keeps updating the history file as it does currently, but doesn't reload its contents after a change in active sessions, so the current yash session stays unaware of commands entered in other shells.
i came up with a patch that makes the behaviour as in bash, however it seems some junk is written in the histfile.
patch follows, unfortunately i didnt find out what markup language this forum uses.
this patch makes it so history between yash instances isn't synchronized
and never reloaded from file during a session.
on exit it's written to file as usual.
this is just like the behaviour of bash.
yash's default behaviour is that you enter a command in term1, then hit
cursor-up in term2, and you suddenly have the command from term1 in the history.
diff --git a/history.c b/history.c
index 6e9143b..86a8524 100644
@@ -1062,7 +1062,7 @@ void add_history(const wchar_t *line)
@@ -1141,6 +1141,7 @@ const histlink_T *get_history_entry(unsigned number)
@@ -1153,12 +1154,17 @@ void start_using_history(void)
diff --git a/yash.c b/yash.c
index 66e8cb3..6d7bd6e 100644
@@ -236,6 +236,12 @@ int main(int argc, char **argv)
+ /* if line editing and interactive and connected to a terminal, start history */
+ if (is_interactive && isatty(STDIN_FILENO) && isatty(STDERR_FILENO))
Thank you for the feature request.
I used to think the bash-like behavior could be implemented by tweaking the yashrc file, but now I think that will not fully work since the abilities of the history and fc built-ins are limited. I consider adding an option to switch the behavior.
Some workarounds that can be done in the current version of yash:
Unset the HISTFILE variable in yashrc, then yash instances do not share history, but the history is lost when you close yash.
To save history over sessions, use the history built-in to save and load the history to and from a file. To save the history automatically when the shell is closed, set the EXIT trap in yashrc. Note that this will overwrite history that may have been written by another shell instance.
thanks for your reply. what came to my mind after spending a couple hours with history.c was that instead of writing pid on start and end, every line could be prefixed by pid in hex, afaik pid can never be > 0xffff so 4 bytes additional should be sufficient. on start the entire hist file is loaded, but after that only lines with own pid will be added to history in "bash mode", in yash mode any. i didn't actually figure out the current purpose of saving the pids, but i saw in strace that other pids active were "killed" - maybe a signal sent? though i dont think this is actually necessary when flock() is used. alternatively the file can be opened in append-only mode, but then duplicates can't be removed (although the writing process could simply not write commands it has buffered in memory).
Yash saves PIDs in the history file and sends signals to other yash processes in order to check if there are other yash processes sharing the same history file. To prevent the command number of history items from increasing forever, yash resets the command number after removing old items, counting from 1 again. This is done only when there are no other shell processes because POSIX requires to do so.