Immediately restore shell history after saving

This is necessary for zsh.

Signed-off-by: Mohammad Alsaleh <CE.Mohammad.AlSaleh@gmail.com>
This commit is contained in:
Mohammad Alsaleh 2015-10-09 02:35:43 +03:00 committed by Bruno Sutic
parent ea3cbcedc6
commit aaec581334
No known key found for this signature in database
GPG Key ID: CAFA7B1B2914ED81

View File

@ -145,6 +145,7 @@ capture_pane_contents() {
save_shell_history() { save_shell_history() {
if [ "$pane_command" = "bash" ]; then if [ "$pane_command" = "bash" ]; then
local history_w='history -w' local history_w='history -w'
local history_r='history -r'
local accept_line='C-m' local accept_line='C-m'
local end_of_line='C-e' local end_of_line='C-e'
local backward_kill_line='C-u' local backward_kill_line='C-u'
@ -155,6 +156,7 @@ save_shell_history() {
# the entire line to be a command. That's why we need -n. # the entire line to be a command. That's why we need -n.
# fc -l only list the last 16 items by default, I think 64 is more reasonable. # fc -l only list the last 16 items by default, I think 64 is more reasonable.
local history_w='fc -lLn -64 >' local history_w='fc -lLn -64 >'
local history_r='fc -R'
local zsh_bindkey="$(zsh -i -c bindkey)" local zsh_bindkey="$(zsh -i -c bindkey)"
local accept_line="$(expr "$(echo "$zsh_bindkey" | grep -m1 '\saccept-line$')" : '^"\(.*\)".*')" local accept_line="$(expr "$(echo "$zsh_bindkey" | grep -m1 '\saccept-line$')" : '^"\(.*\)".*')"
@ -171,9 +173,12 @@ save_shell_history() {
# leading space prevents the command from being saved to history # leading space prevents the command from being saved to history
# (assuming default HISTCONTROL settings) # (assuming default HISTCONTROL settings)
local write_command=" $history_w '$(resurrect_history_file "$pane_id" "$pane_command")'" local write_command=" $history_w '$(resurrect_history_file "$pane_id" "$pane_command")'"
local read_command=" $history_r '$(resurrect_history_file "$pane_id" "$pane_command")'"
# C-e C-u is a Bash shortcut sequence to clear whole line. It is necessary to # C-e C-u is a Bash shortcut sequence to clear whole line. It is necessary to
# delete any pending input so it does not interfere with our history command. # delete any pending input so it does not interfere with our history command.
tmux send-keys -t "$pane_id" "$end_of_line" "$backward_kill_line" "$write_command" "$accept_line" tmux send-keys -t "$pane_id" "$end_of_line" "$backward_kill_line" "$write_command" "$accept_line"
# Immediately restore after saving
tmux send-keys -t "$pane_id" "$end_of_line" "$backward_kill_line" "$read_command" "$accept_line"
fi fi
} }