Skip to content

Instantly share code, notes, and snippets.

@ruph
Last active October 23, 2025 15:59
Show Gist options
  • Save ruph/964df57312ef577eb5da to your computer and use it in GitHub Desktop.
Save ruph/964df57312ef577eb5da to your computer and use it in GitHub Desktop.
zsh settings
# Find and set branch name var if in git repository.
function git_branch_name()
{
branch=$(git symbolic-ref HEAD 2> /dev/null | awk 'BEGIN{FS="/"} {print $NF}')
if [[ $branch == "" ]];
then
:
else
echo '%F{242}['$branch']%f'
fi
}
# Enable prompt substitution
setopt PROMPT_SUBST
# Load zsh color names
autoload -U colors && colors
# Compact prompt: show last 2 dirs + branch
PROMPT='%F{cyan}%2~%f$(git_branch_name) %% '
# Path
export PATH="/opt/homebrew/bin/:$PATH"
# History file and size
export HISTFILE="$HOME/.zsh_history"
export HISTSIZE=10240
export SAVEHIST=10240
# Zsh history settings
setopt HIST_IGNORE_ALL_DUPS # no duplicates at all
setopt HIST_REDUCE_BLANKS # remove extra spaces
setopt HIST_VERIFY # edit before executing history command
setopt EXTENDED_HISTORY # add timestamps
# Critical settings for desired behavior
setopt INC_APPEND_HISTORY # append after each command
setopt NO_SHARE_HISTORY # disables cross-terminal history merging
setopt HIST_EXPIRE_DUPS_FIRST # expire duplicate entries first
# HISTIGNORE can be buggy;
HISTIGNORE="&:[ ]*:exit:ls:bg:fg:history"
# Load history when starting a new shell session
if [[ -f $HISTFILE ]]; then
fc -R
fi
# Keybindings
bindkey -e
WORDCHARS=${WORDCHARS//\/}
# Autocomplete
zstyle :compinstall filename '~/.zshrc'
autoload -Uz compinit
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache
compinit
# Aliases & editor
alias vi='vim'
export EDITOR=vi
# Permissions
umask 002
# Terminal type
export TERM=xterm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment