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

Re: Local history



On Nov 16,  5:27pm, Peter Stephenson wrote:
}
} I'm still thinking about a way of getting a local command history.  My
} particular use is so that zcalc and similar functions can keep their own
} data, separate from the main command history.

It would be nice if the vared builtin could do the same, though that has
some problems: `vared -h' would have to switch from the vared history to
the command history, and probably also disable saving the vared history.
 
} The first thing I tried was manipulating HISTFILE inside the function and
} using fc -R and fc -W.  But this doesn't work too well because the history
} list at the start contains lots of irrelevant bits.  Maybe there's a way of
} truncating the internal list after saving one list and before loading the
} other, but at this point I start to wonder whether I should be doing
} something different.  In particular, incremental appending and history
} sharing will make things well confused.

As Sven mentioned, I've done this before.  The basic trick is that HISTSIZE
truncates the history as soon as you assign to it, so the technique goes
like this:

	local temphist=${TMPPREFIX}hist SAVEHIST=$HISTSIZE
	HISTFILE=$temphist
	fc -W				# Save internal history
	local HISTSIZE=0		# Truncate internal history
	HISTSIZE=$SAVEHIST
	HISTFILE=~/.zcalc-history
	fc -R				# Read previous zcalc history
	# do zcalc stuff ...
	fc -W				# Save zcalc history
	HISTFILE=$temphist
	fc -R				# Reload old history

Then you have to put in the appropriate traps so the old history gets put
back even if the function is interrupted, etc.

On Nov 16, 10:01am, Danek Duvall wrote:
}
} Is this related to the problem I'm having with the following function:

No, it's not really related.

} My normal course is to delete the last few lines of the history.  And
} while they disappear from the end of the history, they reappear at the
} beginning.  Re-running the function -- where those lines don't appear in
} the editor at all -- makes them disappear entirely.

You've probably set the HIST_EXPIRE_DUPS_FIRST option.  When the file is
read back in, everything in it is a duplicate.  So all the existing lines
get expired, except the deleted ones, with the effect that what you wanted
deleted instead gets moved to the top.

Try adding `setopt localoptions no_histexpiredupsfirst' to the function
and see whether that doesn't get back the behavior you wanted.

On Nov 19,  9:40am, Wischnowsky, Sven wrote:
}
} I was thinking about doing it only at the very core, namely supporting
} more than one history list and a way (option to fc or something) to
} switch between these lists.  One could then give them names and use
} $HISTFILE as the prefix of the filenames for the different histories
} (or support per-list flags saying if they are to be saved at all).

This is, approximately, what savehistfile() does at the very end.  Look
for the variable names starting with `remember_'.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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