dotfiles/.zshrc

157 lines
3.8 KiB
Bash
Raw Permalink Normal View History

# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
setopt autocd notify
unsetopt beep
bindkey -v
# End of lines configured by zsh-newuser-install
# Configure cursor
function zle-keymap-select {
2025-06-08 22:48:06 -07:00
zle reset-prompt
case $KEYMAP in
vicmd)
# vim Normal mode
echo -ne '\e[1 q'
;;
viins)
# vim Insert mode
echo -ne '\e[3 q'
;;
*)
# Default mode
echo -ne '\e[3 q'
;;
esac
}
zle -N zle-keymap-select
function zle-line-init {
# New prompt. Reset cursor to underline
echo -ne '\e[3 q'
}
zle -N zle-line-init
function zle-line-finish {
# Prompt complete. Reset cursor to underline
echo -ne '\e[3 q'
}
zle -N zle-line-finish
# SSH completion
zstyle ':completion:*:(ssh|scp|ftp|sftp|rsync):*' hosts $hosts
# The following lines were added by compinstall
zstyle :compinstall filename '/home/d_mcknight/.zshrc'
autoload -Uz compinit
compinit
# End of lines added by compinstall
# Source common envvars
[ -f ~/.profile ] && source ~/.profile
# Prompt
function precmd {
# Check previous command output and notify
if [[ $? != 0 && $? != 130 ]];then
echo -e "⚠️\a"
else
echo -e "\a"
fi
if [ "$EUID" -eq 0 ];then
chrome_color="{red}"
else
chrome_color="{magenta}"
fi
# Static prefix
prefix="%F$chrome_color┌──[%F{cyan}%n%F$chrome_color@%F{cyan}%m%F$chrome_color]-"
# Calculate extra path
if [[ ${debian_chroot} ]]; then
path_extra="(%F{red}${debian_chroot}%F$chrome_color)-"
elif [[ ${VIRTUAL_ENV} ]]; then
rel_venv=$(realpath $VIRTUAL_ENV --relative-to $PWD --relative-base /home)
path_extra="[%F{blue}${rel_venv}%F$chrome_color]-"
else;
path_extra=""
fi
# Static suffix
suffix="(%F{blue}%~%F${chrome_color})"$'\n'"└%F{cyan}%#%F{white} "
PROMPT=$prefix$path_extra$suffix
PS2="%F$chrome_color└%F{cyan}>%F{white} "
}
# Aliases
alias .=source
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias k9=k9s
alias rsync="rsync -e 'ssh -o RemoteCommand=none'"
alias sudosu="sudo ZDOTDIR=$(dirname ${0:a}) zsh"
alias ll='ls -alFh'
alias ls="ls --color=auto"
alias lsl="ls --color=auto -lah"
alias ssh=ssh
2025-06-08 22:48:06 -07:00
# Use tmux for local unelevated shells
if [ -z "${SUDO_USER}" ] && [ -z "${SSH_CONNECTION}" ] && [ -z "${TERM_PROGRAM}" ]; then
tmux new -A -s local_tmux
fi
# Define a function to use autossh with a custom bashrc
function assh() {
remote_file=$(mktemp)
if $(ssh "$@" "cat > ${remote_file}" < ~/.bashrc > /dev/null 2>&1); then
# Successfully copied bashrc to the remote. Source it upon ssh
autossh -t "$@" "bash --rcfile ${remote_file}; rm ${remote_file}"
else
# SSH Config specifies a RemoteCommand; connect normally
autossh "$@"
fi
}
# Use ssh completion for autossh
compdef autossh=ssh
compdef assh=ssh
# Custom dircolors
[ -f ~/.dircolors ] && eval "$(dircolors ~/.dircolors)"
# Kubernetes Completion
which kubectl 1> /dev/null && source <(kubectl completion zsh)
which helm 1> /dev/null && source <(helm completion zsh)
# doctl completion
which doctl 1> /dev/null && source <(doctl completion zsh)
# Start in the home directory
cd ~
# Ensure zinit is installed
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
[ ! -d $ZINIT_HOME ] && mkdir -p "$(dirname $ZINIT_HOME)"
[ ! -d $ZINIT_HOME/.git ] && git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
source "${ZINIT_HOME}/zinit.zsh"
# Load zinit plugins
zinit snippet OMZP::extract
zinit snippet OMZP::colored-man-pages
zinit snippet OMZP::encode64
zinit snippet OMZP::gh
zinit snippet OMZP::pip
zinit snippet OMZP::sudo
zinit light zsh-users/zsh-autosuggestions
zinit light zsh-users/zsh-syntax-highlighting
# Key bindings config
2025-06-08 22:48:06 -07:00
#KEYTIMEOUT=5
# ^[ for esc; ^I for tab
bindkey '^[[Z' autosuggest-accept