dotfiles/zsh/.zshrc
2024-12-30 16:23:42 +00:00

90 lines
2.1 KiB
Bash

alias ls='ls --color=auto'
alias grep='grep --color'
alias vim='nvim'
alias vi='nvim'
alias w3='w3m -T text/html'
# allow for # to be interpreted as a comment on the command line
setopt interactivecomments
# cd tricks
alias -- -='cd -'
setopt auto_cd # there is no binary by that name in your $PATH, your shell will cd into it that directory
# use vi-style keymap
bindkey -v
if [ "${TERM}" = "xterm" ]; then
TERM=xterm-256color
fi
#
# Prompt setup
#
# populate colors arrays
autoload -U colors && colors
# git branch prompt
autoload -Uz vcs_info
setopt prompt_subst
precmd_vcs_info() { vcs_info }
precmd_functions+=( precmd_vcs_info )
# %% escapes '%'
# %S == "standout" => reverses fg/bg
# Surround color codes with '%{' and '%}'
# %r == repo name
# %b == branch name
# %S == relative directory
zstyle ':vcs_info:git*' formats '%%S%r%%s:%{$fg[red]%}%b%{$reset_color%} %S'
zstyle ':vcs_info:git*' actionformats '%%S%r%%s:%{$fg[red]%}%b:%a%{$reset_color%} %S'
function set_prompt() {
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
PROMPT="%B${vcs_info_msg_0_}> %b"
else
PROMPT="%B%m:%~> %b"
fi
}
precmd_functions+=( set_prompt )
#
# Configure SSH auth sock
#
if [ -n "$SSH_AUTH_SOCK" ]; then
if [ "$SSH_AUTH_SOCK" != ~/.ssh/ssh_auth_sock ]; then
ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock
export SSH_AUTH_SOCK=$HOME/.ssh/ssh_auth_sock
fi
fi
# setup SSH keys
if [ -e /usr/bin/keychain ]; then
eval $(/usr/bin/keychain --eval --agents ssh -Q --quiet id_ed25519)
fi
# direnv setup
whence -p direnv &>/dev/null && eval "$(direnv hook zsh)"
# Highlight the current autocomplete option
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
# command line completion for ssh
h=()
if [[ -r ~/.ssh/config ]]; then
h=($h ${${${(@M)${(f)"$(cat ~/.ssh/config)"}:#Host *}#Host }:#*[*?]*})
fi
if [[ -r ~/.ssh/known_hosts ]]; then
h=($h ${${${(f)"$(cat ~/.ssh/known_hosts{,2} || true)"}%%\ *}%%,*}) 2>/dev/null
fi
if [[ $#h -gt 0 ]]; then
zstyle ':completion:*:(ssh|scp|slogin|sftp):*' hosts $h
fi
zstyle :compinstall filename '~/.zshrc'
autoload -Uz compinit
compinit