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

when typing history -c the result is ➜ ~ history -c fc: event not found: -c #739

Closed
googya opened this issue Dec 10, 2011 · 35 comments
Closed

Comments

@googya
Copy link

googya commented Dec 10, 2011

when typing history -c the result is
➜ ~ history -c fc: event not found: -c

I donot understand the result . Is my oh-my-zsh setting wrong?
I install the command with ➜ ~ wget --no-check-certificate https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh and change nothing...

It may be a bug!!

@greg0ire
Copy link

1
Same problem with history -r, see this bug report : https://bugzilla.redhat.com/show_bug.cgi?id=746507

@greg0ire
Copy link

This is because of the alias to fc located here : https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/aliases.zsh

@sorin-ionescu
Copy link
Contributor

history -c does not work with Zsh history. It's a bashism.

@googya
Copy link
Author

googya commented Dec 26, 2011

well, is there other solution to clean the history ?
在 2011-12-26,上午9:32, Sorin Ionescu 写道:

history -c does not work with Zsh history. It's a bashism.


Reply to this email directly or view it on GitHub:
#739 (comment)

@sorin-ionescu
Copy link
Contributor

Delete ~/.zhistory.

history is aliased to fc -l in zsh anyway.

@googya googya closed this as completed Dec 26, 2011
@dmaphy
Copy link

dmaphy commented Dec 27, 2011

history -r does work with zsh and is no bashism. history -r does not work when history is aliased to fc. Would you mind considering this a bug in your configuration? :)

@sorin-ionescu
Copy link
Contributor

The placement of -r matters. history is a built-in alias to fc, according to the man page. Yes, this is a bug.

@greg0ire
Copy link

Ok, I created a new issue here: #789

@asbarron
Copy link

Although this isn't a real fix, if you need to run "history -r" or "history -c" you can make a quick bash script. echo -e '#!/bin/bash\nhistory -c' >> rmhistory.sh && chmod x rmhistory.sh && ./rmhistory.sh

@clarkewd
Copy link

I'm not sure what the takeaway on this is...

So:

  • This is a bug
  • An issue has been filed (but not fixed?)
  • Two years later with a fresh install of zsh / oh-my-zsh history -r still gives this error
  • Apparently the problem is that history is an alias to fc -l 1 and so fc -l 1 -r throws an error if the -r does not come first, as in ( fc -r -l 1)
  • After typing unalias history the command history -r works but this is because the standard history builtin just runs fc -l without the trailing 1

It would be nice if this got fixed.

Also, why can't zsh have some type of history -c functionality? I found this really useful in bash and after reading up on this issue it seems there is no way to do it - very surprising! But why not? zsh is supposed to be

an extended Bourne shell with a large number of improvements, including some features of bash, ksh, and tcsh.

bash's history -c and other history editing commands certainly seem like they would be features worth keeping.

also, @mztriz , I'm not sure what you are trying to do with your example code but it looks wrong.

@mcornella
Copy link
Member

We could convert the current alias into a function, that way we could pass arguments like -r or others before -l, and we could look for -c and delete the history file ($HISTFILE).
I'm working on a solution

@mcornella
Copy link
Member

Here's my solution:

# Show history
fn_history() {
  # Delete the history file if `-c` argument provided.
  # This won't affect the `history` command output until the next login.
  if [[ "${@[(i)-c]}" -le $# ]]; then
    echo -n >| "$HISTFILE"
  else
    fc $@ -l 1
  fi
}

# Timestamp format
case $HIST_STAMPS in
  "mm/dd/yyyy") alias history='fn_history -f' ;;
  "dd.mm.yyyy") alias history='fn_history -E' ;;
  "yyyy-mm-dd") alias history='fn_history -i' ;;
  *) alias history='fn_history' ;;
esac

The history -c part is not perfect, but it's better than nothing..
/cc @LFDM: care to add this to #2422 ?

EDIT: I pushed into https://github.com/mcornella/oh-my-zsh/tree/fix-history-alias

mcornella added a commit to mcornella/ohmyzsh that referenced this issue Jun 15, 2014
This commit changes the history alias into a function which puts
the passed arguments before `-l 1`. It also provides a temporary
workaround to the lack of a `history -c` command in zsh.
This resolves ohmyzsh#739 and resolves ohmyzsh#789.
@clarkewd
Copy link

@mcornella - Thank you!

mcornella added a commit to mcornella/ohmyzsh that referenced this issue Dec 27, 2014
This commit changes the history alias into a function which puts
the passed arguments before `-l 1`. It also provides a temporary
workaround to the lack of a `history -c` command in zsh.

For more information see issues ohmyzsh#739 and ohmyzsh#789.
@mcornella
Copy link
Member

Hi everyone, I pushed a solution at #3422, hopefully you can take a look and 1 if it works well

mcornella added a commit to mcornella/ohmyzsh that referenced this issue Jan 9, 2015
This commit changes the history alias into a function which puts
the passed arguments before `-l 1`. It also provides a temporary
workaround to the lack of a `history -c` command in zsh.

For more information see issues ohmyzsh#739 and ohmyzsh#789.
mcornella added a commit to mcornella/ohmyzsh that referenced this issue Feb 10, 2015
This commit changes the history alias into a function which puts
the passed arguments before `-l 1`. It also provides a temporary
workaround to the lack of a `history -c` command in zsh.

For more information see issues ohmyzsh#739 and ohmyzsh#789.
mcornella added a commit to mcornella/ohmyzsh that referenced this issue Feb 10, 2015
This commit changes the history alias into a function which puts
the passed arguments before `-l 1`. It also provides a temporary
workaround to the lack of a `history -c` command in zsh.

For more information see issues \ohmyzsh#739 and \ohmyzsh#789.
@miguelpalazzo
Copy link

I know this is very old, but had the same issue with history -c and login to bash, typing it and exit was more than enough for me.

@crsuarez
Copy link

You could to this as workaround.

[csuarez@centosdev:~] % truncate -s 0 $HISTFILE 
[csuarez@centosdev:~] % echo $HISTFILE         
/home/csuarez/.zsh_history
[csuarez@centosdev:~] % cat /home/csuarez/.zsh_history
: 1443547857:0;echo $HISTFILE
: 1443547861:0;cat /home/csuarez/.zsh_history
[csuarez@centosdev:~] % 

With this way you don't delete the file, just truncate it.

@atooy
Copy link

atooy commented May 18, 2016

fc: event not found: -c and i can't delete the file .zsh_history...(didn't use sudo permission, afraid there will be something wrong if i delete this file.)

@mcornella
Copy link
Member

You can safely delete the file, it will be recreated next time you start the terminal.

@atooy
Copy link

atooy commented May 18, 2016

Appreciate ur reply! It did recreated and the history was cleared!

@nicksarafa
Copy link

this bug still persists. anybody find a workaround?

@atooy
Copy link

atooy commented Jun 29, 2016

Just delete the file .zsh_history and the history shall be gone. (not so much a bug as a difference between bash and zsh...i think)

@KANGOD
Copy link

KANGOD commented Nov 6, 2016

OMG, from Dec 11, 2011 to Nov 6, 2016, 5 years but the problem is still here!
At least, could you please provide equivalent arguments for fc? Something like fc --reset for history -r, fc --clear for history -c.
Must we deal with the .zsh_history file? This may be a solution for history -c, but obviously not for history -r.

@mcornella
Copy link
Member

There's a PR pending to be tested by more people that fixes both history -c and history -r. Feel free to take a look: #739 (comment)

@keeferrourke
Copy link

Fun fact: it's Sept 2017, and this is this still an issue. history -c does not work with oh-my-zsh.

@notmike-5
Copy link

can't you just cat /dev/null >| $HISTFILE?

@tholu
Copy link

tholu commented Jun 8, 2018

It seems that this also causes a problem with history -d:

➜  ~ history -d 1
fc: event not found: -d

@anmolnagpal
Copy link

Seems it's still an issue on Sept 2018 :)

@mcornella
Copy link
Member

history -c works, history -d might fail but that's a separate issue.

@tholu
Copy link

tholu commented Sep 14, 2018

@mcornella

➜  ~ history -c
fc: event not found: -c
➜  ~ history -d
fc: event not found: -d

@mcornella
Copy link
Member

What does which history print? Do you have the latest version of OMZ installed?

@tholu
Copy link

tholu commented Sep 14, 2018

➜  ~ which history
history: aliased to fc -l 1
➜  ~ zsh --version
zsh 5.6.1 (x86_64-apple-darwin17.7.0)

It worked after upgrading with upgrade_oh_my_zsh!

➜  ~ upgrade_oh_my_zsh
Updating Oh My Zsh
From https://github.com/robbyrussell/oh-my-zsh
 * branch              master     -> FETCH_HEAD
Updating 62b8a70a..315eb773
➜  ~ which history
history: aliased to omz_history

Edit: Nevermind 😄

@mcornella
Copy link
Member

history -c works, history -d might fail but that's a separate issue.

Confirmed that history -d also works with the latest version.

@andreamoro
Copy link

It doesn's seem to work on a Mac OS Catalina though. I receive the history output starting from the line number used as an offset.

@mcornella
Copy link
Member

Can you open a new issue with details?

@John-JV
Copy link

John-JV commented May 28, 2023

rm ~/.zsh_history

then close the terminal when you comeback it's gone

@ohmyzsh ohmyzsh locked as resolved and limited conversation to collaborators May 29, 2023
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