英文:
How to access command history of `tmux` in non-tmux `zsh` session
问题
I had below in my .zshrc
export HISTFILE="$HOME/.zsh_history"
export SAVEHIST=10000
export HISTSIZE=$SAVEHIST
setopt HIST_IGNORE_DUPS
setopt HIST_SAVE_NO_DUPS
setopt HIST_NO_STORE
setopt HIST_IGNORE_SPACE
Later, I realized commands I used inside tmux
session are not available session outside tmux
. I assume they're not in $HOME/.zsh_history
file. So searched internet made these changes:
in my .tmux.conf
set -g history-limit 10000
set -g history-file ~/.zsh_history
& in my .zshrc
file set additional history option
setopt append_history
setopt hist_expire_dups_first
setopt hist_find_no_dups
setopt hist_ignore_all_dups
setopt inc_append_history
After restart, all my command history in ~/.zsh_history
are replaced by the ones that I entered today, all the old commands are gone. I had around 3000+ commands.
I've couple of question
- what might've went wrong with steps that made my history gone
- if
tmux
saved command history, without me explicitly settinghistory-file
option in.tmux.conf
file, can I access that file now? Hoping I could some how restore. - What should I do to save all commands from various tmux session get saved in common file
~/.zsh_history
on exit of the session. - is there any best practice to manage command history, in scenarios like above, so that history can be restored across.
Thanks for your time. Your help is much appreciated.
--
Sudhir.
英文:
I had below in my .zshrc
export HISTFILE="$HOME/.zsh_history"
export SAVEHIST=10000
export HISTSIZE=$SAVEHIST
setopt HIST_IGNORE_DUPS
setopt HIST_SAVE_NO_DUPS
setopt HIST_NO_STORE
setopt HIST_IGNORE_SPACE
Later, I realized commands I used inside tmux
session are not available session outside tmux
. I assume they're not in $HOME/.zsh_history
file.
So searched internet made these changes:
in my .tmux.conf
set -g history-limit 10000
set -g history-file ~/.zsh_history
& in my .zshrc
file set additional history option
setopt append_history
setopt hist_expire_dups_first
setopt hist_find_no_dups
setopt hist_ignore_all_dups
setopt inc_append_history
After restart, all my command history in ~/.zsh_history
are replaced by the ones that I entered today, all the old commands are gone. I had around 3000+ commands.
I've couple of question
- what might've went wrong with steps that made my history gone
- if
tmux
saved command history, without me explicitly settinghistory-file
option in.tmux.conf
file, can I access that file now? Hoping I could some how restore. - What should I do to save all commands from various tmux session get saved in common file
~/.zsh_history
on exit of the session. - is there any best practice to manage command history, in scenarios like above, so that history can be restored across.
Thanks for your time. Your help is much appreciated.
--
Sudhir.
答案1
得分: 1
The tmux history-file
setting is for tmux commands (what you enter after Ctrl+B:), not shell commands. tmux read from ~/.zsh_history
, probably didn't know what to do with the unexpected format, and either deleted it or modified it enough that zsh couldn't understand it. If you're lucky, ~/.zsh_history
could still have all the commands, just modified somehow.
The settings you're now using will write commands to the history file immediately, but only load the history when you start a new session. If you want the history to be available immediately in all sessions, you can remove setopt inc_append_history
and add setopt share_history
(they're incompatible).
For the purposes of history, shell sessions in tmux shouldn't act any different from shell sessions in separate terminal windows, as long as the shell tmux is starting is actually zsh.
英文:
The tmux history-file
setting is for tmux commands (what you enter after <kbd>Ctrl+B</kbd><kbd>:</kbd>), not shell commands. tmux read from ~/.zsh_history
, probably didn't know what to do with the unexpected format, and either deleted it or modified it enough that zsh couldn't understand it. If you're lucky, ~/.zsh_history
could still have all the commands, just modified somehow.
The settings you're now using will write commands to the history file immediately, but only load the history when you start a new session. If you want the history to be available immediately in all sessions, you can remove setopt inc_append_history
and add setopt share_history
(they're incompatible).
For the purposes of history, shell sessions in tmux shouldn't act any different from shell sessions in separate terminal windows, as long as the shell tmux is starting is actually zsh.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论