tags:

views:

227

answers:

2

I work in a place that has gazillions of tools which require tons of options, so I rely on my shell's history significantly. I even back it up every now and then just to make sure I don't lose useful, lengthy commands.

I just typed one of these commands and I want to make sure it's flushed to the history file, but I have a long-running job in the background and I can't type exec zsh. Is there something else I can do in this situation?

(Sure, I could copy and paste it into a file, but it would be more logical for there to exist a flush-history command.)

+1  A: 

To write the shell history to the history file, do

fc -W

fc has some useful flags, see them all in man zshbuiltins.

You can also fully automate reading and writing the history file after each command (thus sharing your history file automatically with each running zsh) by saying setopt -o sharehistory. Read more history-related options in man zshoptions.

pts
Geez, looks like I can't read a man page. Thanks!
a paid nerd
A: 

I also just found:

setopt INC_APPEND_HISTORY

From man zshoptions:

INC_APPEND_HISTORY
   This  options  works like APPEND_HISTORY except that new history
   lines are added to the $HISTFILE incrementally (as soon as  they
   are  entered),  rather  than waiting until the shell exits.  The
   file will still be periodically re-written to trim it  when  the
   number  of  lines grows 20% beyond the value specified by $SAVE-
   HIST (see also the HIST_SAVE_BY_COPY option).
a paid nerd