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 · 32 comments

Comments

@googya
Copy link

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

This comment has been minimized.

Copy link

commented Dec 17, 2011

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

@greg0ire

This comment has been minimized.

Copy link

commented Dec 18, 2011

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

@sorin-ionescu

This comment has been minimized.

Copy link
Contributor

commented Dec 26, 2011

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

@googya

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Contributor

commented Dec 26, 2011

Delete ~/.zhistory.

history is aliased to fc -l in zsh anyway.

@googya googya closed this Dec 26, 2011

@dmaphy

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Dec 27, 2011

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

@greg0ire

This comment has been minimized.

Copy link

commented Dec 30, 2011

Ok, I created a new issue here: #789

@mztriz

This comment has been minimized.

Copy link

commented Apr 21, 2014

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

This comment has been minimized.

Copy link

commented Jun 15, 2014

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

This comment has been minimized.

Copy link
Collaborator

commented Jun 15, 2014

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

This comment has been minimized.

Copy link
Collaborator

commented Jun 15, 2014

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/oh-my-zsh that referenced this issue Jun 15, 2014

Change history alias to function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Jun 15, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.
@clarkewd

This comment has been minimized.

Copy link

commented Jun 15, 2014

@mcornella - Thank you!

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Jul 1, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Jul 1, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Jul 15, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Jul 17, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Jul 21, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Aug 28, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Aug 31, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Sep 13, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Oct 22, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Nov 6, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Nov 6, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Nov 9, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Dec 13, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Dec 13, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Dec 15, 2014

Change history alias into a function
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 robbyrussell#739 and resolves robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Dec 18, 2014

Change history alias into a function
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 robbyrussell#739 and robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Dec 27, 2014

Change history alias into a function
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 robbyrussell#739 and robbyrussell#789.
@mcornella

This comment has been minimized.

Copy link
Collaborator

commented Jan 2, 2015

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/oh-my-zsh that referenced this issue Jan 9, 2015

Change history alias into a function
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 robbyrussell#739 and robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Feb 1, 2015

Change history alias into a function
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 robbyrussell#739 and robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Feb 10, 2015

Change history alias into a function
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 robbyrussell#739 and robbyrussell#789.

mcornella added a commit to mcornella/oh-my-zsh that referenced this issue Feb 10, 2015

Change history alias into a function
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 \robbyrussell#739 and \robbyrussell#789.
@miguelpalazzo

This comment has been minimized.

Copy link

commented Aug 18, 2015

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

This comment has been minimized.

Copy link

commented Sep 29, 2015

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Collaborator

commented May 18, 2016

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

@atooy

This comment has been minimized.

Copy link

commented May 18, 2016

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

@nicksarafa

This comment has been minimized.

Copy link

commented Jun 28, 2016

this bug still persists. anybody find a workaround?

@atooy

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Collaborator

commented Nov 7, 2016

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

This comment has been minimized.

Copy link

commented Sep 22, 2017

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

@notmike-5

This comment has been minimized.

Copy link

commented Jan 14, 2018

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

@tholu

This comment has been minimized.

Copy link

commented Jun 8, 2018

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

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

This comment has been minimized.

Copy link

commented Sep 14, 2018

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

@mcornella

This comment has been minimized.

Copy link
Collaborator

commented Sep 14, 2018

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

@tholu

This comment has been minimized.

Copy link

commented Sep 14, 2018

@mcornella

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

This comment has been minimized.

Copy link
Collaborator

commented Sep 14, 2018

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

@tholu

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Collaborator

commented Sep 15, 2018

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.