Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Feature Request: fc -C to clear history and reset counter



On 19.05.20 20:28, Roman Perepelitsa wrote:
> On Tue, May 19, 2020 at 5:53 PM Markus Näher <markus.naeher@xxxxxxx> wrote:
>> but it's missing -C for clearing the history completely.
>
> Why not restart zsh with `exec zsh`?
>
> Roman.
>

And how do I load the project-specific history (and _only_ that one) in
the new instance ?

The new instance will execute all startup scripts (and that's OK because
of all other things like themes, settings, aliases, ...) and load the
"default" history.
So I still can not have the new history _without_ the "default" history
but counter starting at 1. This means I'm in the same situation again.


I have a second use case for clearing the history. I only started my
request with the use case that's easier to explain.

For bash, I wrote a function that allows me to edit the _whole_ history
(not only the last entry like fc), even reorder entries. This is it:

history_edit() {
  if [ "${EDITOR}" == "" ]
  then
    echo "EDITOR must be set."
    return 1
  fi

  tempdir="/tmp/${USER}"
  tempfile="/tmp/${USER}/bash_history.$$"

  if [ ! -d "${tempdir}" ]
  then
    mkdir -p "${tempdir}"
    chmod 770 "${tempdir}"
  fi

  history -w "${tempfile}"
  ${EDITOR} "${tempfile}"
  history -c
  history -r "${tempfile}"
  rm -f "${tempfile}"
}

I just cannot work without that. All of my working style is adapted to
having that option.

Markus



Messages sorted by: Reverse Date, Date, Thread, Author