Skip to content

Allow history file name customization #102

Closed

Description

@ekoeppen

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.

Activity

  1. jaysh commented on Feb 5, 2015

    @jaysh

    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/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.

    Thanks,
    Jay

  2. ridiculousfish commented on Feb 5, 2015

    @ridiculousfish
    Member

    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?

  3. jaysh commented on Feb 5, 2015

    @jaysh

    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:

    fish_history_filename=/some/path/to/the/history fish
    

    Then I'd have that profile as a launcher shortcut somewhere.

  4. ridiculousfish commented on Feb 5, 2015

    @ridiculousfish
    Member

    Thanks, that makes sense.

  5. added 2 commits that reference this issue on Feb 5, 2015
    0e14141
    9103d2c
  6. krader1961 commented on Jan 9, 2016

    @krader1961
    Contributor

    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.

  7. floam commented on Feb 16, 2016

    @floam
    Member

    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.

  8. krader1961 commented on Feb 23, 2016

    @krader1961
    Contributor

    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.

  9. krader1961 commented on Feb 27, 2016

    @krader1961
    Contributor

    If someone sets $FISH_HISTFILE (which I've decided to use rather than $HISTFILE) to a relative path should fish

    1. always expand that path relative to the $PWD at the time a command is logged, or
    2. 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.

  10. ridiculousfish commented on Feb 27, 2016

    @ridiculousfish
    Member

    That's a pretty funny question. What do bash and zsh do?

  11. ridiculousfish commented on Feb 27, 2016

    @ridiculousfish
    Member

    Also if I set FISH_HISTFILE, do I lose my history from this session and instead pick up whatever was in that other file?

  12. krader1961 commented on Feb 27, 2016

    @krader1961
    Contributor

    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.

  13. krader1961 commented on Feb 27, 2016

    @krader1961
    Contributor

    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.

  14. ridiculousfish commented on Feb 27, 2016

    @ridiculousfish
    Member

    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.

  15. 9 remaining items

  16. tomassedovic commented on May 17, 2017

    @tomassedovic
    Contributor

    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.

    The location of the history file will be:

    $XDG_DATA_HOME/fish/<session_id>_history
    

    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_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.

  17. added a commit that references this issue on May 27, 2017
    5deff73
  18. modified the milestones: fish 2.7.0, fish-future on Jul 24, 2017
  19. faho commented on Mar 7, 2018

    @faho
    Member

    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.

  20. locked as resolved and limited conversation to collaborators on Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions