Bash and zsh can share $HISTFILE
In zsh
, I type bash
to enter bash. Under my current setting, bash only save history after I press Ctrl+D (back to zsh
)
The syntax of bash and zsh is different enough that you'd end up with many commands that don't work when copied to the other shell
For me, most commands work, but we should pay attention to the timestamp:
echo '14:56'
is written to .zsh_history
at 2022-01-11 14:57, when I press Ctrl+D)
With peco
, I get the history:
^*_*^ > \d{4}-\d{2}-\d{2}\s\d{2}:\d{2}\s{2} Regexp [1987 (1/67)]
2022-01-11 14:57 e .zsh_history
2022-01-11 14:55 bash
2022-01-11 14:57 echo '14:56'
2022-01-11 14:57 echo $HISTFILE
2022-01-11 14:57 print $HISTFILE
2022-01-11 14:57 print -l $HISTFILE
2022-01-11 14:57 e .zsh_history
2022-01-11 14:57 ls
2022-01-11 14:55 history -i -n 1 | le
2022-01-11 14:55 ~
2022-01-11 14:55 -
In the .zsh_history
: 1641884226:0;ls
: 1641884234:17;e .zsh_history
print -l $HISTFILE
print $HISTFILE
echo $HISTFILE
echo '14:56'
: 1641884154:100;bash
: 1641884257:9;e .zsh_history
: 1641884338:0;e .zsh_history
: 1641880817:3534;e history_config_wf.zsh
: 1641884353:0;~
My setting with peco
(in .zshrc
):
BUFFER=$(history -i -2000 | eval $tac | cut -c 8- | peco --initial-filter="Regexp" --query "\\d{4}-\\d{2}-\\d{2}\\s\\d{2}:\\d{2}\\s{2} $BUFFER")