Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Editing history stack during runtime?
- X-seq: zsh-users 12663
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: "zsh users" <zsh-users@xxxxxxxxxx>
- Subject: Re: Editing history stack during runtime?
- Date: Fri, 29 Feb 2008 19:22:18 -0800
- In-reply-to: <2d460de70802291142u4bdf7c94qa330ff9dad1324f0@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <2d460de70802281709n1847611cp6cb9a5273e212bae@xxxxxxxxxxxxxx> <080229084310.ZM17549@xxxxxxxxxxxxxxxxxxxxxx> <2d460de70802291142u4bdf7c94qa330ff9dad1324f0@xxxxxxxxxxxxxx>
On Feb 29, 8:42pm, Richard Hartmann wrote:
}
} I want to take the session history, i.e. what was typed since last login,
} and edit that. Then, I want whatever I save to replace the session
} history.
I have a vague recollection of something like this having been posted
before, but not since we added "always" blocks and similar fun, so:
edit_hist () {
emulate -LR zsh
unsetopt append_history inc_append_history share_history
# You may want these in this case even if not otherwise:
# setopt hist_expire_dups_first hist_ignore_all_dups
# The following gibberish creates a unique tempfile
# and makes sure that we'll write the whole history
local SAVEHIST=$HISTSIZE HISTFILE=${:-=(:)}$$
# Make sure we write a new file and rename to the tempfile
setopt no_hist_save_by_copy
# Finally, the actual useful work
fc -W
{
if ${VISUAL:-${EDITOR:-vi}} $HISTFILE
then
# Truncate internal history to discard deleted lines
HISTSIZE=0
HISTSIZE=$SAVEHIST
fc -R
fi
} always {
rm -f $HISTFILE
}
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author