我想重新启动我的 zsh 会话,因为我保持一个持久的 tmux 会话并~/.zshrc
经常更改并执行source ~/.zshrc
. 但是我意识到随着时间的推移这会变慢(例如for i in
seq 50; do source ~/.zshrc; echo "a"; done
开始快速打印'a'并且很快变慢)。
我在这里阅读了重新启动 zsh 的建议,建议只需运行zsh
or 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
只需用一个新实例替换您正在运行的 zsh 实例:
exec
是一个shell 内置命令,目的是(参见zshbuiltins
手册页):为什么它变慢了......我的第一个猜测是,你在你的 PATH 中重新定义了
zshrc
,也许一个目录在一个相当慢的驱动器上。因此,在您每次搜索 后zshrc
,您的搜索路径都会变得越来越长。并且每次都zsh
必须重新散列越来越多的目录......请阅读我对另一个问题的回答如何改善这种情况。