You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To have separate histories when using e.g. screen or logging in to a machine via multiple sessions, it should be possible to customize the history file name, for example using an environment variable. See ekoeppen@ccfac2c for a possible implementation.
Reacted by Aaron Gyes, Tomáš Šedovič and Adam Uhlíř
@ridiculousfish - would you consider a pull request for it? This milestone was assigned a while back, so I thought I would double check.
My use case is the same as this one, and I was thinking of the same approach. Rather than making it specifically configurable, you could just set an environment variable to essentially namespace the histories.
With a slightly tweaked implementation, I believe this would also solve #1156 too if it could be set to /dev/null as the environment variable. This would be the approach I'm in favor of, so at least a workaround is available for anyone interested in #1156.
An environment variable is certainly easy to implement on the fish side. Out of curiosity, how do you plan to set the variable? Would you do it manually (set -x ...) or in a config file someplace?
My initial use case is within terminator. I experimented by creating a profile and selected the "Run a custom command instead of my shell" and configured it to have:
fish_history_filename=/some/path/to/the/history fish
Then I'd have that profile as a launcher shortcut somewhere.
Sorry, but I vote no to this request. Three and a half years after the issue was opened only one person has said "me too". If you really need isolated history files then you should be using Linux containers or a similar technology to create a namespace for the shell.
I think this may help implement sessions with working suspend/resume for OS X's Terminal.app. (see /etc/bashrc_Apple_Terminal for what Apple does with bash.)
I'm a "Me Too!", I want to try to make local sessions work from within fish by manually managing/abusing the history.
Okay, I've changed my mind. However, I think this should use the same HISTFILE env var name that bash and zsh use. Thanks for PR#1940, @jaysh, but it has some problems with the code not to mention the lack of unit tests and changes to the documentation. If you don't mind I'll borrow your idea and fix the problems.
If someone sets $FISH_HISTFILE (which I've decided to use rather than $HISTFILE) to a relative path should fish
always expand that path relative to the $PWD at the time a command is logged, or
anchor it (i.e., convert to an absolute path) at the time the variable is set?
This is something of a rhetorical question because I think it's pretty clear option 1 will cause so many problems it's not even worth considering. I only ask because the original pull-request implemented that behavior. As did my first rewrite of that change. Unless someone can explain why option 1 is preferable I'm going to implement option 2.
I have no idea what bash/zsh do. Zsh in particular is such a rat maze of behavior I wouldn't even pretend that I knew how it behaves despite using it for 7+ years and you'd have to pay me to figure out what it does.
Your second question is more interesting. It's not clear to me what happens or should happen. Any new commands are logged to the new $FISH_HISTFILE as best I can tell from limited human testing and unit tests. But what does that mean for older history that is unique to the current shell? When does an interactive fish instance decide to rewrite the current fish history file? If fish merely concatenated commands to the history file rather than removing old entries for the same unique command this would presumably be straightforward to answer. But the duplicate elimination complicates things.
Which means I don't really understand when the history file is rewritten and neither did the person who created the original change. It also means the documentation doesn't answer this question unless I have a reading comprehension problem.
P.S., for anyone paying attention. The dialog on this issue is a canonical example of why seemingly simple enhancement requests are almost never simple.
When does an interactive fish instance decide to rewrite the current fish history file?
Every 25 (kVacuumFrequency) items, with an initially randomized counter.
The history is conceptually just a list of commands. Running a command appends to that list, and up-arrow traverses backwards through them. It seems natural that setting FISH_HISTFILE switches over to a different list, so it would not contain any prior commands.
If we believe this (and I do) then the implementation is very straightforward. History is already instanced (see e.g. history_with_name), so setting FISH_HISTFILE should simply set the reader_data_t::history field to a new (or existing) instance. This avoids a bunch of ugly concurrency issues and is definitely my preferred approach.
A minor change required is to replace history_with_name would history_with_path; right now history_filename infers the path from the name, but we would instead want the path to be explicitly settable.
Based on the comments on the pull request above, here's the proposed implementation:
The history file will be controlled solely by the FISH_HISTFILE environment variable. The variable represents a session ID that the history files will use. It is not a path to a file or directory.
As you can see, setting FISH_HISTFILE to fish will result in the current path of the history file, so that's going to be the default value. If FISH_HISTFILE is unset or set to default, we will use the default value (fish).
If FISH_HISTFILE is set to an empty string, no history will be stored (like the private/incognito mode in web browsers).
If the value changes in a single shell session, the location will be updated accordingly.
For posterity: The variable was renamed to fish_history, and it contains a "session ID", not a filename. That means the file ends up being called {$fish_history}_history and {$fish_history}_read_history for things entered via read.
Activity
jaysh commentedon Feb 5, 2015
I would also very much like this feature 👍
@ridiculousfish - would you consider a pull request for it? This milestone was assigned a while back, so I thought I would double check.
My use case is the same as this one, and I was thinking of the same approach. Rather than making it specifically configurable, you could just set an environment variable to essentially namespace the histories.
With a slightly tweaked implementation, I believe this would also solve #1156 too if it could be set to
/dev/nullas the environment variable. This would be the approach I'm in favor of, so at least a workaround is available for anyone interested in #1156.Thanks,
Jay
ridiculousfish commentedon Feb 5, 2015
An environment variable is certainly easy to implement on the fish side. Out of curiosity, how do you plan to set the variable? Would you do it manually (
set -x ...) or in a config file someplace?jaysh commentedon Feb 5, 2015
Music to my ears :)
My initial use case is within
terminator. I experimented by creating a profile and selected the "Run a custom command instead of my shell" and configured it to have:Then I'd have that profile as a launcher shortcut somewhere.
ridiculousfish commentedon Feb 5, 2015
Thanks, that makes sense.
Introduce an environment to set the history location.
Introduce an environment variable to set the history location.
krader1961 commentedon Jan 9, 2016
Sorry, but I vote no to this request. Three and a half years after the issue was opened only one person has said "me too". If you really need isolated history files then you should be using Linux containers or a similar technology to create a namespace for the shell.
floam commentedon Feb 16, 2016
I think this may help implement sessions with working suspend/resume for OS X's Terminal.app. (see /etc/bashrc_Apple_Terminal for what Apple does with bash.)
I'm a "Me Too!", I want to try to make local sessions work from within fish by manually managing/abusing the history.
krader1961 commentedon Feb 23, 2016
Okay, I've changed my mind. However, I think this should use the same HISTFILE env var name that bash and zsh use. Thanks for PR#1940, @jaysh, but it has some problems with the code not to mention the lack of unit tests and changes to the documentation. If you don't mind I'll borrow your idea and fix the problems.
krader1961 commentedon Feb 27, 2016
If someone sets
$FISH_HISTFILE(which I've decided to use rather than$HISTFILE) to a relative path should fish$PWDat the time a command is logged, orThis is something of a rhetorical question because I think it's pretty clear option 1 will cause so many problems it's not even worth considering. I only ask because the original pull-request implemented that behavior. As did my first rewrite of that change. Unless someone can explain why option 1 is preferable I'm going to implement option 2.
ridiculousfish commentedon Feb 27, 2016
That's a pretty funny question. What do bash and zsh do?
ridiculousfish commentedon Feb 27, 2016
Also if I set FISH_HISTFILE, do I lose my history from this session and instead pick up whatever was in that other file?
krader1961 commentedon Feb 27, 2016
I have no idea what bash/zsh do. Zsh in particular is such a rat maze of behavior I wouldn't even pretend that I knew how it behaves despite using it for 7+ years and you'd have to pay me to figure out what it does.
Your second question is more interesting. It's not clear to me what happens or should happen. Any new commands are logged to the new
$FISH_HISTFILEas best I can tell from limited human testing and unit tests. But what does that mean for older history that is unique to the current shell? When does an interactive fish instance decide to rewrite the current fish history file? If fish merely concatenated commands to the history file rather than removing old entries for the same unique command this would presumably be straightforward to answer. But the duplicate elimination complicates things.Which means I don't really understand when the history file is rewritten and neither did the person who created the original change. It also means the documentation doesn't answer this question unless I have a reading comprehension problem.
krader1961 commentedon Feb 27, 2016
P.S., for anyone paying attention. The dialog on this issue is a canonical example of why seemingly simple enhancement requests are almost never simple.
ridiculousfish commentedon Feb 27, 2016
Every 25 (
kVacuumFrequency) items, with an initially randomized counter.The history is conceptually just a list of commands. Running a command appends to that list, and up-arrow traverses backwards through them. It seems natural that setting FISH_HISTFILE switches over to a different list, so it would not contain any prior commands.
If we believe this (and I do) then the implementation is very straightforward. History is already instanced (see e.g.
history_with_name), so setting FISH_HISTFILE should simply set thereader_data_t::historyfield to a new (or existing) instance. This avoids a bunch of ugly concurrency issues and is definitely my preferred approach.A minor change required is to replace
history_with_namewouldhistory_with_path; right nowhistory_filenameinfers the path from the name, but we would instead want the path to be explicitly settable.9 remaining items
tomassedovic commentedon May 17, 2017
Based on the comments on the pull request above, here's the proposed implementation:
The history file will be controlled solely by the
FISH_HISTFILEenvironment variable. The variable represents a session ID that the history files will use. It is not a path to a file or directory.The location of the history file will be:
Couple of examples:
FISH_HISTFILE="fish"->~/.local/share/fish/fish_history{,.*}FISH_HISTFILE="banana"->~/.local/share/fish/banana_history{,.*}As you can see, setting
FISH_HISTFILEtofishwill result in the current path of the history file, so that's going to be the default value. IfFISH_HISTFILEis unset or set todefault, we will use the default value (fish).If
FISH_HISTFILEis set to an empty string, no history will be stored (like the private/incognito mode in web browsers).If the value changes in a single shell session, the location will be updated accordingly.
Make the history session configurable
faho commentedon Mar 7, 2018
For posterity: The variable was renamed to
fish_history, and it contains a "session ID", not a filename. That means the file ends up being called{$fish_history}_historyand{$fish_history}_read_historyfor things entered viaread.Add a --private option to launch fish in private mode
Add a --private option to launch fish in private mode
Add a --private option to launch fish in private mode
Add a --private option to launch fish in private mode
Add a --private option to launch fish in private mode
terminal: persist command history per tab
terminal: persist command history per tab
Add a --private option to launch fish in private mode