'Properly setting up .zshrc on Mac
everyday, when I start Terminal on my Mac for the first time after a shut down, it takes a long time to start. Today, after Oh-My-Zsh auto-updated, Terminal doesn't start at all: it keeps creating multiple .zcompdump and the prompt never appears in my terminal window. I think my .zshrc was not well formatted and something broke after the update.
I'm not an expert so I rely on guides to setup my environments.
I'm on Monterey 12.3.1 and zsh 5.8.1.
When I first set tup my environments, I installed Homebrew and brew install pyenv and pyenv install Python 3.9.7 (I need 3.9.7 for a project), set 3.9.7 as my global default, put
eval "$(pyenv init --path)" in my .zprofile and .zshrc files. I also added alias brew='env PATH="${PATH//$(pyenv root)\/shims:/}" brew' to my .zshrc file to fix a warning.
Then I brew install the Pure prompt and put autoload -U promptinit; promptinit prompt pure at the end of my .zshrc file.
I brew install the ZSH Autosuggestions, Completions and Syntax Highlighting plugins. Following the plugin installation instructions, I put source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh and
source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh at the end of my .zshrc.
The plugins instructions tell me to put source ~/.zshrc. If I do, when I start Terminal it creates multiple .zcompdump and never stops.
If I put source $ZSH/oh-my-zsh.sh, Terminal creates 2 files, .zcompdump and .zcompdump-MY-COMPUTER-HOST-NAME-5.8.1 and everything seems to work.
In the end, my .zshrc looks like this after I removed all the commented out OMZ stuff:
# Pyenv
# To fix brew doctor's warning ""config" scripts exist outside your system or Homebrew directories"
alias brew='env PATH="${PATH//$(pyenv root)\/shims:/}" brew'
eval "$(pyenv init -)"
# Path to your oh-my-zsh installation.
export ZSH="/Users/prospero/.oh-my-zsh"
ZSH_THEME=""
# Uncomment one of the following lines to change the auto-update behavior
zstyle ':omz:update' mode auto # update automatically without asking
# Uncomment the following line to change how often to auto-update (in days).
zstyle ':omz:update' frequency 14
# Which plugins would you like to load?
plugins=(macos)
# Autosuggestions Plugin
# This speeds up pasting w/ autosuggest
# https://github.com/zsh-users/zsh-autosuggestions/issues/238
pasteinit() {
OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}
pastefinish() {
zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish
# Completions Plugin
# To activate these completions, add the following to your .zshrc:
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
autoload -Uz compinit
compinit
fi
# You may also need to force rebuild `zcompdump`:
# rm -f ~/.zcompdump; compinit
# Additionally, if you receive "zsh compinit: insecure directories" warnings when attempting to load these completions, you may need to run this:
# chmod -R go-w '$(brew --prefix)/share/zsh'
# Syntax Highlighting Plugin
# To activate the syntax highlighting, add the following at the end of your .zshrc:
# source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# If you receive "highlighters directory not found" error message, you may need to add the following to your .zshenv:
# export ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR=$(brew --prefix)/share/zsh-syntax-highlighting/highlighters
# Pure Prompt
autoload -U promptinit; promptinit
prompt pure
source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh
source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source $ZSH/oh-my-zsh.sh
Is it a correct and well formed .zshrc?
The positions of the Pure prompt and plugins stuff are correct?
The position of the source $ZSH/oh-my-zsh.sh is correct?
Is there anything I can do reduce the startup time of the terminal when I start it for the first time after a shut down?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
