Skip to content

Instantly share code, notes, and snippets.

@tobyjsullivan
Last active September 18, 2026 05:42
Show Gist options
  • Select an option

  • Save tobyjsullivan/79d87f2b279f7b59a8d0f9b6b2aedf53 to your computer and use it in GitHub Desktop.

Select an option

Save tobyjsullivan/79d87f2b279f7b59a8d0f9b6b2aedf53 to your computer and use it in GitHub Desktop.
.zshrc
# share history across sessions
setopt inc_append_history
setopt share_history
# Setup tab completion
autoload -Uz compinit
compinit
# fix opt+backspace on paths
autoload -U select-word-style
select-word-style bash
# customize prompt
setopt prompt_subst
autoload -Uz vcs_info add-zsh-hook
## git ref
# ref: https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#vcs_005finfo-Variables
zstyle ':vcs_info:git:*' check-for-changes true
zstyle ':vcs_info:git:*' formats ' (%b)%c%u'
zstyle ':vcs_info:git:*' actionformats ' (%b|%a)%c%u'
## pwd: every directory but the last becomes its first letter, or a dot and a letter
typeset -g prompt_cwd=''
function precmd_prompt()
{
local p=${(%):-%~}
local -a parts=( ${(s:/:)p} )
local i
for (( i = 1; i < $#parts; i++ )); do
[[ $parts[i] == .* ]] && parts[i]=${parts[i][1,2]} || parts[i]=${parts[i][1,1]}
done
# the split drops the leading slash of an absolute path, so put it back
prompt_cwd="${p%%[^/]*}${(j:/:)parts}"
prompt_cwd=${prompt_cwd//\%/%%}
vcs_info
}
add-zsh-hook precmd precmd_prompt
PS1='${prompt_cwd}%F{red}%B${vcs_info_msg_0_}%b%f %# '
# Recommended by brew doctor
export PATH="/usr/local/sbin:$PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment