Skip to content

Instantly share code, notes, and snippets.

@brianjbayer
Created November 19, 2023 06:21
Show Gist options
  • Save brianjbayer/547e3a71c455f4c4778f9e08599e16f2 to your computer and use it in GitHub Desktop.
Save brianjbayer/547e3a71c455f4c4778f9e08599e16f2 to your computer and use it in GitHub Desktop.
Configure a basic Mac user profile (~/.zshrc)

Configure Your User Profile (~/.zshrc)

Once you have Homebrew installed, it is really helpful to have your user profile ~/.zshrc setup. This will give you your aliases, paths, environment, etc.

🍺 Homebrew in its installation output instructs you to add it to your ~/.zshrc.

⚙️ You may find it useful to both automate the installation of your common profile files as well as keep them under source code control even if just locally.

I use a GitHub repository for my basic standard macOS ~/.zshrc with an installation script. This installation script installs the .zshrc file in another directory so that it can be put under git and then soft links it to ~/.zshrc. This .zshrc file contains the configuration needed for Homebrew.

You can use my repository to install a basic Mac ~/.zshrc with Homebrew support and then customize it if you want.

:octocat: Just follow the README of my GitHub Repository mac-dev-zsh-profile


Sample ~/.zshrc

If you wish to create your own profile here is a sample that may be useful...

# ----------------------------------
# Z shell for MacOS profile
# ----------------------------------

#-- HOMEBREW --
# Add Homebrew package management to shell environment
# Add brew shellenv to your ~/.zshrc file"
# This is inside baseball from the brew install script
# Determine where brew itself is installed based on Intel vs Apple Silicon
[[ `uname -m` == "arm64" ]] && homebrew_prefix="/opt/homebrew" || homebrew_prefix="/usr/local"
eval "$(${homebrew_prefix}/bin/brew shellenv)"
unset homebrew_prefix

# -- UTILITIES (ETC.) --
# Enable git autocomplete
autoload -Uz compinit && compinit

# -- ALIASES --
# Basic Aliases
alias lsa='ls -al '
alias cls='clear '

# Git Aliases
alias ga='git add '
alias gb='git branch '
alias gc='git commit '
alias gcm='git commit -m '
alias gd='git diff '
alias go='git checkout '
alias gs='git status '
alias golo='git log '

# -- PATH --
# Nothing yet

#--- PROMPT ---
# Zshell specific includes git branch in prompt
# Simple function to get the git branch
parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
# NOTE: PROMPT_SUBST must be set for variable/special character
# expansion
setopt PROMPT_SUBST
# Prompt:username@shorthostname currentdirectoryonly (gitbranchname)%
PROMPT='%n@%m %1~%F{green}$(parse_git_branch)%f%# '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment