|
# Minimal zsh config with PS1 and fzf history |
|
|
|
# Enable colors |
|
autoload -U colors && colors |
|
|
|
# Git branch function (standalone, no Oh My Zsh needed) |
|
git_branch() { |
|
local branch=$(git symbolic-ref --short HEAD 2>/dev/null) |
|
if [[ -n "$branch" ]]; then |
|
local dirty="" |
|
[[ -n $(git status --porcelain 2>/dev/null) ]] && dirty=" %{$fg[yellow]%}✗" |
|
echo " %{$fg_bold[blue]%}git:(%{$fg[red]%}$branch%{$fg[blue]%})$dirty%{$reset_color%}" |
|
fi |
|
} |
|
|
|
# Enable prompt substitution |
|
setopt PROMPT_SUBST |
|
|
|
# PS1 - Robbyrussell style prompt |
|
# Green arrow if last command succeeded, red if failed |
|
# Cyan current directory + git info |
|
PROMPT='%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )%{$fg[cyan]%}%c%{$reset_color%}$(git_branch) ' |
|
|
|
# History settings |
|
HISTFILE=~/.zsh_history |
|
HISTSIZE=50000 |
|
SAVEHIST=50000 |
|
setopt SHARE_HISTORY |
|
setopt HIST_IGNORE_DUPS |
|
setopt HIST_IGNORE_SPACE |
|
|
|
# zsh-history-substring-search (Up/Down arrows) |
|
# Type partial command, then use arrows to search history |
|
# Install: brew install zsh-history-substring-search |
|
if [[ -f $(brew --prefix)/share/zsh-history-substring-search/zsh-history-substring-search.zsh ]]; then |
|
source $(brew --prefix)/share/zsh-history-substring-search/zsh-history-substring-search.zsh |
|
bindkey '^[[A' history-substring-search-up # Up arrow |
|
bindkey '^[[B' history-substring-search-down # Down arrow |
|
fi |
|
|
|
# fzf fuzzy history search (Ctrl+R) |
|
# Install: brew install fzf |
|
if command -v fzf &>/dev/null; then |
|
fzf-history-widget() { |
|
local selected=$(fc -rln 1 | fzf --height 40% --reverse --tac +s --tiebreak=index) |
|
if [[ -n "$selected" ]]; then |
|
BUFFER="$selected" |
|
CURSOR=$#BUFFER |
|
zle reset-prompt |
|
fi |
|
} |
|
zle -N fzf-history-widget |
|
bindkey '^R' fzf-history-widget |
|
fi |
|
|
|
# zsh-autosuggestions (accept with → or End) |
|
# Install: brew install zsh-autosuggestions |
|
[[ -f $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh ]] && \ |
|
source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh |
|
|
|
# zsh-syntax-highlighting (MUST be last) |
|
# Install: brew install zsh-syntax-highlighting |
|
[[ -f $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]] && \ |
|
source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh |