Skip to content

Allow read to not store history #1504

Closed

Description

@sugar700

Sometimes, the user may want to read without storing history. However, there is no option to not store the history.

Activity

  1. added this to the fish-future milestone on Sep 21, 2014
  2. Asuza commented on Oct 29, 2015

    @Asuza

    @xfix, does this only happen from the command line? I used read in a script and it didn't seem to store that history anywhere (as far as I know).

  3. cben commented on Feb 12, 2016

    @cben
    Contributor

    Aha, found it!
    It's not stored in regular shell history but read has its own readline history, which can be accessed by up arrow when you run read again.
    It's even persisted (~/.config/fish/fish_read_history) and shared immediately among fish instances.
    There is already an option that controls it:

    • -m NAME or --mode-name=NAME specifies that the name NAME should be used to save/load the history file. If NAME is fish, the regular fish history will be available.

    but even empty --mode-name="" doesn't disable storing (it writes to ~/.config/fish/_history).

    👍, one of the use cases of read is entering passwords without storing them anywhere, and this subverts that...
    Obviously once silent mode (#838) is implemented, it should also disable storing.

    There should probably also be an independent flag to control storing. (Or redefine --mode-name=""? IMHO that'd be hard to discover; seeing something like --no-history when scanning the --help would make it clearer that it is stored by default.)

  4. krader1961 commented on Feb 12, 2016

    @krader1961
    Contributor

    Just do read -m /dev/null var.

  5. cben commented on Feb 22, 2016

    @cben
    Contributor

    @bucaran: Oh I see, ... | read var does not store any history. I suppose stdin is not a tty so it skips the history/readline code path.
    I don't think that's obvious from help read, will try to impove the doc as a starting point.

    @krader1961 That happens to work but not quite intentionally, -m doesn't expect a full path. strace:

    open("/home/bpaskinc/.config/fish//dev/null_history.o8WTAF", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0600) = -1 ENOENT (No such file or directory)
    open("/home/bpaskinc/.config/fish//dev/null_history.SIk6NR", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0600) = -1 ENOENT (No such file or directory)
    open("/home/bpaskinc/.config/fish//dev/null_history.M1Ti13", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0600) = -1 ENOENT (No such file or directory)
    open("/home/bpaskinc/.config/fish//dev/null_history.FuFveg", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0600) = -1 ENOENT (No such file or directory)
    open("/home/bpaskinc/.config/fish//dev/null_history.JdDIrs", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0600) = -1 ENOENT (No such file or directory)
    open("/home/bpaskinc/.config/fish//dev/null_history.69MVEE", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0600) = -1 ENOENT (No such file or directory)
    open("/home/bpaskinc/.config/fish//dev/null_history.2u88RQ", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0600) = -1 ENOENT (No such file or directory)
    open("/home/bpaskinc/.config/fish//dev/null_history.0vFm52", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0600) = -1 ENOENT (No such file or directory)
    open("/home/bpaskinc/.config/fish//dev/null_history.XgoAif", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0600) = -1 ENOENT (No such file or directory)
    open("/home/bpaskinc/.config/fish//dev/null_history.0hmOvr", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0600) = -1 ENOENT (No such file or directory)
    
  6. krader1961 commented on Feb 23, 2016

    @krader1961
    Contributor

    That read -m /dev/null treats the path as a simple word used in constructing a path is arguably a bug. It's certainly the most natural way of telling it not to use a history file on a UNIX platform. Although the definition of the option says nothing about specifying a path name I think making /dev/null a special-case is reasonable. But we should not allow arbitrary paths; i.e., we should raise an error if the "name" includes a forward or backward slash. It would probably be a good idea to also allow an empty string to inhibit use of a history file.

  7. krader1961 commented on Jul 1, 2017

    @krader1961
    Contributor

    Now that issue #102 has been addressed, and we have the FISH_HISTORY var for choosing the history file, we should change read to honor that var and deprecate the --mode-name flag. By deprecate I mean "print a warning telling the user to use FISH_HISTORY and ignore the flag." There are no uses of the flag (or the -m short flag) in any fish, Fisherman, or OMF scripts.

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

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions