Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enter private mode or stop retaining new history while retaining current history during an active session #7589

Closed
etcusrvar opened this issue Dec 30, 2020 · 5 comments
Milestone

Comments

@etcusrvar
Copy link

etcusrvar commented Dec 30, 2020

I would like to know if this is currently possible, or if this is a feature that could be implemented.

I would like something similar to what I have implemented in zsh (Note: this does have some bugs, but it meets my wants for now.)

Fish supports private mode-- this allows you to start a new session without retaining history.
But you can't enter private mode after the session has started.
The fish_private_mode variable is read-only and can't be changed by the user or via script.

Fish supports set fish_history, setting it to an empty string, which means "history will not be stored at all".
But once set fish_history is called during an active session, all history in the current session is gone.

$ sh -c 'env HOME=$(mktemp -d) fish'
Welcome to fish, the friendly interactive shell
Type `help` for instructions on how to use fish
x@x /h/x> foo
fish: Unknown command: foo
x@x /h/x [127]> bar
fish: Unknown command: bar
x@x /h/x [127]> history
bar
foo
x@x /h/x> set fish_history
  # up arrow recalls nothing; `foo`,`bar`, and `history` are gone
x@x /h/x> history
x@x /h/x> 
  # up arrow now recalls `history`; `foo` and `bar` are gone

Also, the history variable is read-only and can't be changed by the user or via script.

I understand from the docs that "the most common use case for this feature is to avoid leaking private or sensitive history when giving a presentation." But this requires either starting a new session with no history, or losing current history if in the middle of a session.

I understand that set fish_history foo switches to a different "session"-- a different history and file. I like this feature and use it, in both fish and zsh (via different ZDOTDIR paths on startup). But this is a different use case.

I'm leaning toward something like #1156 (comment) before private mode was implemented in fish.
But before I try going down the path of copying and renaming and manipulating history files (as I currently do in zsh), I wanted to see if there was a better (or any) alternative.

What might work is simply allowing fish_private_mode to be changed.

fish, version 3.1.2
Linux 5.9.16 x86_64
xterm-256color

@zgracem
Copy link
Contributor

zgracem commented Dec 30, 2020

I currently use this as a workaround, fwiw:

function incognito -d "Toggle fish's private mode on and off"
    if set -q fish_private_mode
        exec fish
    else
        exec fish --private
    end
end

@etcusrvar
Copy link
Author

etcusrvar commented Dec 30, 2020

Thanks @zgracem. That doesn't retain the current session's history, which is the point of opening this issue.
Unfortunately, this function also has no effect if fish_history is set, due to #7590.

ridiculousfish added a commit to ridiculousfish/fish-shell that referenced this issue Jan 3, 2021
@ridiculousfish ridiculousfish added this to the fish 3.2.0 milestone Jan 3, 2021
@ridiculousfish
Copy link
Member

With 118f710, fish_private_mode can be dynamically toggled on and off by setting the fish_private_mode variable. If fish_private_mode is set and non-empty, then any commands are not written to disk, but may still be recalled with up-arrow.

@etcusrvar
Copy link
Author

etcusrvar commented Jan 3, 2021

Awesome-- tried and works exactly like I would expect!

@etcusrvar
Copy link
Author

etcusrvar commented Jan 23, 2021

Until this lands in a fish release, I've been using a plugin I created in the meantime-- https://github.com/etcusrvar/fish-profile.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants