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

multiline ZLE w/ bash-like single line .zsh_history...?




Hi,

I like the multiline capability of ZLE, but when history lines are
appended to the .zsh_history file, I would like for multiline commands
to be morphed into a single line (similar to what bash does).

This is because I sometimes like to grep (or even edit) .zsh_history,
and if I find the command I'm looking for, I want to be able copy and
paste it into a new shell w/o having to make any changes to it.

For example, if I enter a multiline command like so:

  % echo \
  `> foo

... And then use 'up-line-or-history', I'll get to see it still as a
multiline in ZLE (which is good).  The line is not yet in my
.zsh_history file, because I have not set the INC_APPEND_HISTORY
option.

If I exit the shell and inspect .zsh_history, I see these two lines:

  echo \\
  foo

In bash (which does not have the excellent multiline capability), I
would see a single line, like so:

  echo foo

If I simply copy and paste the multiline entry, it will not behave the
way my original command did because of the double slash '\\'...

Is there a way to get zsh to be bash-like when it writes to the
history file...?  I'm willing to lose the multiline niceness for old
commands in new shells.

I have zsh setup to keep a smaller internal history and a larger
external history with these settings:

  HISTSIZE=9999  # internal
  SAVEHIST=99999 # external
  HISTFILE=$HOME/.zsh_history

And I have these helper aliases defined:

  alias history="fc -IA ; cat $HISTFILE" # access external history too
  alias h=history                        # a shortcut...

So when I want to find a really old command (usually because
history-incremental-search-backward failed to find it), I may do
something like this:

  h | grep 'some old cmd'

And here, again, having the history saved as a single line would be
helpful, because the output would be ready for copy and paste...

Maybe I do not know the "zsh way" to best do what I'm hoping to be
able to do...  Can I keep multiline in ZLE but lose it in HISTFILE?

Thanks for your time and consideration!

- Tor




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