![.zshrc 配置,順序重要嗎?](https://rvso.com/image/178464/.zshrc%20%E9%85%8D%E7%BD%AE%EF%BC%8C%E9%A0%86%E5%BA%8F%E9%87%8D%E8%A6%81%E5%97%8E%EF%BC%9F.png)
既然 zsh 是 Mac 的預設終端,我決定嘗試將我的 .bashrc 首選項複製到 .zshrc。
我已經擁有了大部分需要的東西,但我還有一些小東西要補充。我對製作 .zshrc 檔案一無所知,所以我在 Google 上進行了大量搜尋。
我已經想出了這個,但在嘗試將其組織成更乾淨的東西之前,這些事情的順序重要嗎?
抱歉,這真的是一團糟。
#################
# Output Prompt #
#################
NEWLINE=$'\n'
PROMPT="%F{cyan}%n%f@%F{green}%m%f %F{011}%~%f \$vcs_info_msg_0_ ${NEWLINE}%% "
# RPROMPT=\$vcs_info_msg_0_
###########
# ALIASES #
###########
alias ls='ls -GFh'
# TODO: DO MORE RESEARCH ON THESE
# alias l='colorls --group-directories-first --almost-all'
# alias ll='colorls --group-directories-first --almost-all --long' # detailed list view
# case insensitive path-completion from - https://scriptingosx.com/2019/07/moving-to-zsh-part-5-completions/
# zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
# partial completion suggestions - from https://scriptingosx.com/2019/07/moving-to-zsh-part-5-completions/
# zstyle ':completion:*' list-suffixes
# zstyle ':completion:*' expand prefix suffix
# E-TODO
export LSCOLORS=gxfxbxdxcxegedabagacad
# The following lines were added by compinstall
zstyle ':completion:*' completer _complete _ignored _approximate
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' matcher-list 'm:{[:lower:]}={[:upper:]} m:{[:lower:][:upper:]}={[:upper:][:lower:]}'
zstyle :compinstall filename '/Users/ryan/.zshrc'
autoload -Uz compinit
compinit
# End of lines added by compinstall
autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':completion:*:*:cdr:*:*' menu selection
autoload -Uz vcs_info
precmd_vcs_info() { vcs_info }
precmd_functions+=( precmd_vcs_info )
setopt prompt_subst
setopt HIST_IGNORE_DUPS # Prevents duplicate commands from being saved the command line history
setopt HIST_IGNORE_SPACE # Remove command lines from the history when the first character is a space
setopt HIST_REDUCE_BLANKS # Remove superfolus blanks from each command being added to the history list
zstyle ':vcs_info:git:*' formats '%F{196}(%b)%f'
zstyle ':vcs_info:*' enable git
答案1
這取決於,有時他們確實像上面解釋的德文郡一樣,但如果他們彼此沒有任何關係,那麼他們就不重要了。例如,如果您定義了一堆未在 .zshrc 中使用的別名,或者不依賴 .zshrc 中的任何內容,那麼您可以將它們放在您想要的任何位置。如果它們向終端提供某種輸出,那麼輸出將按照您在 .zshrc 檔案中的順序顯示。
答案2
zsh 會執行您體內的命令.zshrc
,就像您在終端機中鍵入它們一樣。順序確實很重要,例如,在定義變數之前不能使用變數。