0

Now that zsh is the default terminal for Mac, I've decided to try and replicate my .bashrc preferences to .zshrc.

I have most of what I need, but I still have some minor things to add. I didn't know anything about making a .zshrc file, so I did a lot of searching on Google.

I've come up with this, but before trying to organize it into something a bit cleaner, does the order of any of these things matter?

Sorry that it's really an ugly mess.

#################
# 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
1

It depends, sometimes they do like Devon explained above, but if they don't have anything to do with each other then no they don't matter. For example if you define a bunch of aliases that aren't being used in your .zshrc or don't depend on anything in your .zshrc then you can put them anywhere you want. If they provide some kind of output to terminal then the output would appear in the order you have them in your .zshrc file.

1

zsh runs the commands in you .zshrc as if you typed them in your terminal. The order does matter, e.g. you cannot use variables before you defined them.

1
  • Strictly speaking, you can use variables before you set them, but you wouldn't get the values you expected. A better example is using autoloaded functions before actually loading them. There's a couple of examples of autoloading functions in the given file.
    – Kusalananda
    Aug 12 '20 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.