I would like to restart my zsh session, because I keep one persistent tmux session and change ~/.zshrc often and do source ~/.zshrc. However I realized that this gets slower over time (eg. for i inseq 50; do source ~/.zshrc; echo "a"; done starts printing 'a' s fast and gets slower quickly).
I read the suggestions here to restart zsh and the suggestion is to simply run zsh or zsh -l. However if I do that, I create a 'nested' zsh session, if I understood it correctly. By that I mean:
# 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 I have a tmux session with multiple windows and a command history that I care to keep persistent. That's why I am looking for a sustainable solution.
Bonus question: does anyone have any idea why source ~/.zshrc might be slowing down?
# 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 31 Answer
Just replace you're running zsh instance with a new one:
exec zsh exec is a shell builtin command with the purpose to (see zshbuiltinsman page):
Replace the current shell with command rather than forking.
Why it is getting slower... my first speculation would be, that you redefine PATH in your zshrc, with maybe one directory on a rather slow drive. So after every time you source your zshrc, your search path gets longer and longer. And every time zsh has to rehash more and more directories...
Please read my answer to another question how to improve that situation.
8