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

Re: deleting history



On Jun 24, 12:30pm, dado wrote:
} Subject: deleting history
}
} is there a way of deleting entries in the history?

Only by deleting all of it.

} also, is there a way of preventing commands from being added to the
} history?
} I'm not talking about preceding them with a blank.

Only by deleting all of it.

} Let say I'll issue a bunch of different commands, going back to them
} in no particular order. When I'm done, I'd like those commands only to
} be
} erased. Something like
} do_not_log_this_commands_for_good_but_just_for_now.

The obvious thing would be to start another shell and then exit it when
you're done, so I won't ask why not.

function toggle-temporary-history() {
    if (( ${TEMPHIST:-0} > HISTSIZE ))			# If alternate
    then
	eval "HISTSIZE=0; HISTSIZE=$HISTSIZE"		# Flush history
	SAVEHIST=$TEMPHIST				# Resume saving
	fc -R						# Reload saved
	unset TEMPHIST					# Toggle off
    else
	TEMPHIST=$SAVEHIST				# Toggle on
	(( SAVEHIST < HISTSIZE )) && SAVEHIST=$HISTSIZE	# Remember all
	fc -W						# Save history
	SAVEHIST=0					# Prevent save
    fi
}

The "flush history" step isn't strictly necessary, but in case the file
somehow became smaller than HISTSIZE (say, you reset HISTSIZE larger
while temporary history was toggled on) this assures that the entire
temporary history gets erased.

In 3.1.6 (not 3.0.6; both are coming soon) you can even bind the above
to a keystroke.  Note that the above doesn't work very well if you have
two shells sharing the history or another shell incrementally appending
to it; in that case you may want to pass a temp file name to the two
"fc" commands above.

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



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