omz_history -p doesn't work as expected
MoAlkhateeb opened this issue · comments
Describe the bug
-
In bash, in order to not save the history for the current session you use
history -c
. To do the same in zsh you usehistory -p
instead. -
Using ohmyzsh,
history -c
clears the history file completely instead of just not saving the history for the current session. -
The history file path is stored in the
HISTFILE
environment variable. By default, it's the$HOME/.zsh_history
file. -
When using oh-my-zsh,
history
is aliased to theomz_history
function. which is defined as follows:
Lines 2 to 18 in bf713e2
-
When attempting to clear the history completely, you run
history -c
or its equivalentomz_history -c
. This clears the history file completely as intended. -
When attempting to not save history for the current session but not tampering with the history file, you would run
history -p
. -
However, when attempting to run
history -p
with ohmyzsh this results in runningbuiltin fc -l "$@" 1
. Here"$@"
is set to-p
which results inbuiltin fc -l -p 1
. This indeed does not save the current session history to the original history file. However: -
What this causes is that the
HISTFILE
environment variable is overwritten with the value1
. A file named1
is automatically created in the current working directory and the session history is stored in it. Any attempt to remove the file within the session will result in it being recreated whenever any interactive command is executed until the session is exited. -
When the session is exited, the file still exists.
References:
Steps to reproduce
- Start a new session
- Navigate to a directory with no files called
1
. echo $HISTFILE
should result in$HOME/.zsh_history
by default.- run
history -p
echo $HISTFILE
results in1
.ls
you find a file called1
.
Expected behavior
history -p
unsets theHISTFILE
environment variable.- No file is created.
- Current session history is not preserved beyond the session.
Screenshots and recordings
OS / Linux distribution
macOS Sonoma 14.4.1
Zsh version
5.9
Oh My Zsh version
master (bf713e2)
Terminal emulator
iTerm2
If using WSL on Windows, which version of WSL
None
Additional context
No response
I absolutely agree. @mcornella what do you think about? I'd remove
Line 16 in 5bff59f
fc -l "$@"
instead of printing the whole history.I came up with the same conclusion, replacing the else block with builtin fc -l "$@"
. That way the user can have some control over the underlying fc
call and at the same time users executing just history
are not left out.
Should I submit a PR for this? I would love to.
Sure! Let's discuss in the PR with @mcornella
Great! #12338
Thanks @MoAlkhateeb!