Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: multiline ZLE w/ bash-like single line .zsh_history...?
- X-seq: zsh-users 15630
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: multiline ZLE w/ bash-like single line .zsh_history...?
- Date: Mon, 06 Dec 2010 20:47:48 -0800
- In-reply-to: <20101206190255.4B3CA1ED691A@xxxxxxxxxxxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20101206190255.4B3CA1ED691A@xxxxxxxxxxxxxxx>
On Dec 6, 11:02am, zsh@xxxxxxxx wrote:
}
} 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).
In a sufficiently new zsh, there is a zshaddhistory hook function
(like precmd, chpwd, etc.). You can manipulate the history any way
you like; e.g., the following saves each line of the multiline as a
single line in the history:
zshaddhistory() { print -sr "${(z)1%%$'\n'}"; return 1 }
(And I finally get another chance to point out to PWS why it's a good
thing that (z) converts newlines into semicolons ... but it also
reveals a bug in the handling of here-documents ... moving that over
to zsh-workers.) [Bash appears to ignore here-documents entirely?]
As was discussed in a lengthy thread earlier this year, the full multi-
line command "lingers" in the interactive history for one cycle even
if zshaddhistory returns nonzero.
} 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.
There is not a way to get the interactive history and the history file
to behave differently from one another, except by using more than one
history file (the "fc -p" example for zshaddhistory in the manual).
You could, for example, do
zshaddhistory() {
fc -p ${HISTFILE}_bash_format $HISTSIZE $SAVEHIST
print -sr "${(z)1%%$'\n'}"
return 0
}
which would still save in zsh native format in $HISTFILE, but keep a
bash-format copy in a parallel file.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author