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
{{ message }}
Repository navigation
Support for anonymous session (no logging to history) #1156
In some session I know I will have to type commands that contain sensitive information, and in this case I would prefer not to have those commands written to history at all.
In bash, this can be done by doing unset HISTFILE before running any commands. You can still use arrow up to get to previous commands from that session, but once you terminate the shell, the commands are gone. I haven't found a similar feature in fish? I know I can prefix each command with a space, but that's not really a good alternative when you have to run more than just a couple of commands.
I might be missing something somewhere in my search but this seems like a valid enough place to ask. Is there currently a way to clear the history in fish shell?
I've come up with an even hackier (but effective) solution until this is properly supported in fish.
In ~/.config/fish/config.fish, add:
set-g __fish_history_file ~/.local/share/fish/fish_history
set-g __fish_history_backup_file $__fish_history_file.bak
set-g __fish_history_pid_file $__fish_history_file.pid
iftest-f$__fish_history_backup_file
read-l histpid <$__fish_history_pid_file
# If the pid no longer has open files, restore the original history fileifnot lsof -p$histpid>/dev/null
mv-f -- $__fish_history_backup_file $__fish_history_file
rm-f -- $__fish_history_pid_file
endend
Then, create a new function to disable history (e.g. ~/.config/fish/functions/disable_history.fish)
function disable_history --description"Disable history for the current session"# Do not continue if there is an existing backup filetest-f$__fish_history_backup_file; andreturn# Keep track of the pid responsible for disabling historyecho %self >$__fish_history_pid_file
# Redirect history to /dev/nullmv-f -- $__fish_history_file $__fish_history_backup_file
andln-sf -- /dev/null $__fish_history_file
end
When the function is executed, history will be disabled for the current session and any other sessions that are launched while the current session is active (i.e. the PID exists). Once the current session exits, new sessions will write their history as normal.
Another function could be written to manually re-enable history, rather than every time a new session is launched.
@bucaran It creates a symbolic link from ~/.local/share/fish/fish_history to /dev/null, which is a special device that discards anything written to it. It's important that the original history is first renamed to ~/.local/share/fish/fish_history.bak, though, else you'd lose all your history. Use with caution! 😉
Hmm, I'm not quite sure I understand the question, but I'll take another stab at answering it...
It means none of the history is stored anywhere on disk after you've typed disable_history. If the symlink wasn't created, fish would automatically create a new history file and start writing to it, which is what we're trying to avoid.
Closing this as a dup of #102. Once I've addressed that issue it will be possible to tell fish not to log any commands both before invoking the fish shell and while it is running. Not to mention having distinct history log files for specialized needs.
I'm adding my support for an anonymous shell session. Just because you can do it using other means doesn't diminish the value of first class support by your shell, like web browsers.
@jspiro: No need for "adding support". In 3.0 you can set $fish_history to the empty string (this was supposed to work in 2.7.0 but crashed when you did this on startup).
On Mar 7, 2018, 3:30 PM -0800, Fabian Homborg ***@***.***>, wrote:
@jspiro: No need for "adding support". In 3.0 you can set $fish_history to the empty string (this was supposed to work in 2.7.0 but crashed when you did this on startup).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
That’s much more complicated than necessary, like saying you can clear your browser history. That’s all I’m suggesting.
@jspiro: What exactly is more complicated here? You start an "anonymous session" by setting that variable. If you want something that has a more explicitly "anonymous" name, make your own function. E.g.
function fishcognito
env fish_history='' fish
end
I don't really see how we can make it any less complicated without making it less general.
Activity
IngCr3at1on commentedon Aug 21, 2015
I might be missing something somewhere in my search but this seems like a valid enough place to ask. Is there currently a way to clear the history in fish shell?
ridiculousfish commentedon Aug 21, 2015
Try
history --clearIngCr3at1on commentedon Aug 21, 2015
Awesome, thanks @ridiculousfish
I had tried
history --cbut didn't think to try the word clear for some reason lolzanchey commentedon Sep 11, 2015
There's a hacky implementation: add
commandline " "to yourfish_prompt.gechr commentedon Feb 6, 2016
I've come up with an even hackier (but effective) solution until this is properly supported in fish.
In
~/.config/fish/config.fish, add:Then, create a new function to disable history (e.g.
~/.config/fish/functions/disable_history.fish)When the function is executed, history will be disabled for the current session and any other sessions that are launched while the current session is active (i.e. the PID exists). Once the current session exits, new sessions will write their history as normal.
Another function could be written to manually re-enable history, rather than every time a new session is launched.
gechr commentedon Feb 6, 2016
@bucaran It creates a symbolic link from
~/.local/share/fish/fish_historyto/dev/null, which is a special device that discards anything written to it. It's important that the original history is first renamed to~/.local/share/fish/fish_history.bak, though, else you'd lose all your history. Use with caution! 😉gechr commentedon Feb 6, 2016
Hmm, I'm not quite sure I understand the question, but I'll take another stab at answering it...
It means none of the history is stored anywhere on disk after you've typed
disable_history. If the symlink wasn't created, fish would automatically create a new history file and start writing to it, which is what we're trying to avoid.krader1961 commentedon Mar 1, 2016
Closing this as a dup of #102. Once I've addressed that issue it will be possible to tell fish not to log any commands both before invoking the fish shell and while it is running. Not to mention having distinct history log files for specialized needs.
jspiro commentedon Mar 7, 2018
I'm adding my support for an anonymous shell session. Just because you can do it using other means doesn't diminish the value of first class support by your shell, like web browsers.
That said, prepending your command with a single space is a subtle but effective way to do this that 99% of people don't know: https://stackoverflow.com/questions/8473121/execute-command-without-keeping-it-in-history
faho commentedon Mar 7, 2018
@jspiro: No need for "adding support". In 3.0 you can set
$fish_historyto the empty string (this was supposed to work in 2.7.0 but crashed when you did this on startup).jspiro commentedon Mar 8, 2018
faho commentedon Mar 8, 2018
@jspiro: What exactly is more complicated here? You start an "anonymous session" by setting that variable. If you want something that has a more explicitly "anonymous" name, make your own function. E.g.
I don't really see how we can make it any less complicated without making it less general.