Files
dotfiles/zsh/.zshrc
2025-06-18 10:31:29 +01:00

146 lines
4.0 KiB
Bash

# Use emacs keymap as the default.
bindkey -e
# load fish-like auto-suggestions
[[ -f ~/.zsh/zsh-autosuggestions.zsh ]] && source ~/.zsh/zsh-autosuggestions.zsh
ZSH_AUTOSUGGEST_STRATEGY=(history)
# History file config
HISTSIZE="1000000"
SAVEHIST="5000000"
HISTFILE="/home/fergus/.cache/zsh/histfile"
mkdir -p "$(dirname "$HISTFILE")"
# History options
setopt HIST_FCNTL_LOCK
unsetopt APPEND_HISTORY
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_ALL_DUPS
unsetopt HIST_SAVE_NO_DUPS
unsetopt HIST_FIND_NO_DUPS
setopt HIST_IGNORE_SPACE
unsetopt HIST_EXPIRE_DUPS_FIRST
setopt SHARE_HISTORY
unsetopt EXTENDED_HISTORY
# General options
setopt autocd extendedglob
# fzf extra shell features
command -v fzf >/dev/null 2>&1 && source <(fzf --zsh)
export FZF_DEFAULT_COMMAND="fd --type f --strip-cwd-prefix --hidden --follow --exclude .git"
export FZF_TMUX="1"
# configure completion
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
zstyle ':completion:*' list-colors "$\{(s.:.)LS_COLORS}"
zstyle ':completion:*' menu no
command -v fzf >/dev/null 2>& zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls --color $realpath'
autoload -U promptinit; promptinit
autoload -U compinit && compinit
# init opam module if installed
[[ ! -r /home/fergus/.opam/opam-init/init.zsh ]] || source /home/fergus/.opam/opam-init/init.zsh > /dev/null 2> /dev/null
# more intuitive history search keys
bindkey '^p' history-search-backward
bindkey '^n' history-search-forward
# init prompt
command -v starship >/dev/null 2>& eval "$(starship init zsh)"
# run fastfetch on new shells
command -v fastfetch >/dev/null 2>& fastfetch
# automatically enter a tmux session
tmux start-server
if [ -z "$TMUX" ]; then
tmux has-session -t dev 2> /dev/null && tmux new-session || tmux new-session -s dev
fi
# load kitty shell integrations
if test -n "$KITTY_INSTALLATION_DIR"; then
export KITTY_SHELL_INTEGRATION="no-rc"
autoload -Uz -- "$KITTY_INSTALLATION_DIR"/shell-integration/zsh/kitty-integration
kitty-integration
unfunction kitty-integration
fi
# add direnv hook if installed
command -v direnv >/dev/null 2>& eval "$(direnv hook zsh)"
# export common env vars
export EDITOR="nvim"
export SHELL="/usr/bin/zsh"
export TERM="xterm-kitty"
export GPG_TTY="$(tty)"
export TIMEFMT="$'
================
CPU %P
user %*U
system %*S
total %*E
'"
# add common bin dirs to path
export PATH="/home/fergus/.local/bin:$PATH"
export PATH="/home/fergus/.local/bin:/home/fergus/.cargo/bin:$PATH"
# import any extra env that doesn't want to be kept in vsc
[[ -f ~/.extra-env ]] && source ~/.extra-env
# add common options
alias -- cp='cp -r'
alias -- mkdir='mkdir -p'
alias -- rm='rm -vr'
alias -- sudo='sudo '
alias -- :q=exit
alias -- c=cargo
alias -- cat=bat
alias -- cl=clear
alias -- find=fd
alias -- grep=rg
alias -- top=btop
# editor aliases
alias -- v='eval "$EDITOR"'
alias -- vim='eval "$EDITOR"'
alias -- vf='eval "$EDITOR" $(fzf)'
# git aliases
alias -- gC='git commit -m'
alias -- gD='git diff --staged -w'
alias -- gP='git push'
alias -- gPf='git push --force-with-lease'
alias -- gS='git switch -c'
alias -- gaa='git add --all'
alias -- gau='git add -u'
alias -- gc='git commit'
alias -- gca='git commit --amend --no-edit'
alias -- gd='git diff -w'
alias -- gmf='git merge --ff-only'
alias -- gp='git pull'
alias -- gprc='gh pr create'
alias -- gr='git rebase'
alias -- gs='git switch'
alias -- gst='git status'
# ls aliases
if [[ command -v eza >/dev/null 2>&1 ]]; then
alias -- ls='eza -lh -s=name --git --group-directories-first --no-permissions --icons --no-user'
alias -- lsa='eza -lha -s=name --git --group-directories-first --no-permissions --icons --no-user'
alias -- lsg='eza -lh -s=name --git --group-directories-first --git-ignore --no-permissions --icons --no-user'
alias -- lsp='eza -lha -s=name --git --icons --group-directories-first'
else
echo "eza not installed using regular ls"
alias -- ls="ls -l"
alias -- lsa="ls -la"
fi
[[ -f /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]] && source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
ZSH_HIGHLIGHT_HIGHLIGHTERS+=()