我想重新启动我的 zsh 会话,因为我保留一个持久的 tmux 会话并~/.zshrc
经常更改并执行source ~/.zshrc
。但是我意识到这会随着时间的推移而变慢(例如,for i in
seq 50; do source ~/.zshrc; echo "a"; done
开始快速打印 'a' 然后很快变慢)。
我读了这里关于重新启动 zsh 的建议,建议是简单地运行zsh
或zsh -l
。但是,如果我这样做,我会创建一个“嵌套”的 zsh 会话,如果我理解正确的话。我的意思是:
# Simulate slowed zsh session
for i in `seq 50`; do source ~/.zshrc; echo "a"; done
# use zsh to make it faster "child" zsh
zsh
# confirm fast
source ~/.zshrc; # fast
# revert back to "parent" zsh
exit
# confirm old slow session is still there
source ~/.zshrc; # slow
我有一个包含多个窗口和命令历史记录的 tmux 会话,我希望保留这些历史记录。因此,我正在寻找一个可持续的解决方案。
附加问题:有人知道为什么source ~/.zshrc
可能会放慢速度吗?
# Path to your oh-my-zsh installation.
export ZSH="/Users/username/.oh-my-zsh"
ZSH_THEME="themename"
# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
)
source $ZSH/oh-my-zsh.sh
# activate zsh-syntax-highlighting (brew install zsh-syntax-highlighting)
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
function proxyON() {
...redacted
}
function proxyOFF(){
http_proxy=
https_proxy=
HTTP_PROXY=
HTTPS_PROXY=
export http_proxy https_proxy HTTP_PROXY HTTPS_PROXY
}
function nukeDS_Store(){
find ~/Projects/mys/ -name '.DS_Store' -delete
}
function reload-ssh() {
ssh-add -e /Library/OpenSC/lib/opensc-pkcs11.so >> /dev/null
if [ $? -gt 0 ]; then
echo "Failed to remove previous card"
fi
ssh-add -s /Library/OpenSC/lib/opensc-pkcs11.so
}
alias fastBuild='mvn install --offline -DskipTests=true'
## History Settings
# set history size
export HISTSIZE=1000000
#save history after logout
export SAVEHIST=1000000
##history file
export HISTFILE=~/.zhistory
##save only one command if 2 common are same and consistent
setopt HIST_IGNORE_DUPS
##add timestamp for each entry
setopt EXTENDED_HISTORY
##have seperate history for each
setopt nosharehistory
##dont append into history file
setopt NOINC_APPEND_HISTORY
# Set java version
export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_191`
# Maven
export M3_HOME="/Applications/apache-maven-3.6.0" # replace n.n.n with appropriate version
export M3=$M3_HOME/bin
export PATH=$M3:$PATH
## set node version
export PATH="/usr/local/opt/node@8/bin:$PATH"
## pic-tools
source /Projects/pic-tools/scripts/*.env
答案1
只需用新的实例替换您正在运行的 zsh 实例:
exec zsh
exec
是shell 内置命令命令的目的是(参见zshbuiltins
手册页):
用命令代替当前 shell,而不是用 forking。
为什么它越来越慢...我的第一个猜测是,你在 中重新定义了 PATH zshrc
,可能有一个目录位于一个相当慢的驱动器上。因此,每次你找到 之后zshrc
,你的搜索路径就会越来越长。而且每次都zsh
必须重新散列越来越多的目录...
请阅读我的回答另一个询问如何改善这种情况。