dotfiles/.zshrc

95 lines
2.6 KiB
Bash

# Print user@host into title so terminal tabs are correct
# Despite being called precmd() this executes after process exits, before prompt
precmd() { echo -ne "\033]0;${USER}@${HOST}\007" }
# Generic navigation keybinds
bindkey "^[[H" beginning-of-line # HOME
bindkey "^[[F" end-of-line # END
bindkey "^[[3~" delete-char # DEL
bindkey '^R' history-incremental-search-backward
# Global aliases
alias ct="clear && task"
alias grep='grep -EIs --color=auto --exclude-dir=.git'
# Use exa if we have it
# I don't want this in .profile because it's not completely backward compatible with ls
if [ -e /usr/bin/exa ]; then
alias ls="exa --icons"
fi
# Live-update ZSH history for all shells
setopt appendhistory
setopt incappendhistory
setopt sharehistory
# Case-insensetive tab completion
autoload -Uz compinit && compinit
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
# Edit long command lines in vim with ^x^e
autoload -U edit-command-line
zle -N edit-command-line
bindkey '^x^e' edit-command-line
# Load any kind of system-local stuff
[[ ! -f ~/.zshrc.local ]] || source ~/.zshrc.local
# Transient prompt
_prompt () {
local retval=$?
# Echo compact prompt
if (( $_prompt_compact )); then
if [ -z "$SSH_CLIENT" ] && [ -z "$SSH_TTY" ]; then
echo "\e[1;30;42m `date +%H:%M:%S` \e[32;40m\e[0m "
else
echo "\e[1;30;43m `date +%H:%M:%S` \e[33;40m\e[0m "
fi
return
fi
# Echo main prompt
'/usr/bin/starship' prompt --terminal-width="$COLUMNS" --keymap="${KEYMAP:-}" --status="$STARSHIP_CMD_STATUS" --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --cmd-duration="${STARSHIP_DURATION:-}" --jobs="$STARSHIP_JOBS_COUNT"
}
setopt prompt_subst
_zle-line-init() {
[[ $CONTEXT == start ]] || return 0
# Start regular line editor
(( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[1]
zle .recursive-edit
local -i ret=$?
(( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[2]
# If we received EOT, we exit the shell
if [[ $ret == 0 && $KEYS == $'\4' ]]; then
_prompt_compact=1
zle .reset-prompt
exit
fi
# Line edition is over. Shorten the current prompt.
_prompt_compact=1
zle .reset-prompt
unset _prompt_compact
if (( ret )); then
# Ctrl-C
zle .send-break
else
# Enter
zle .accept-line
fi
return ret
}
zle -N zle-line-init _zle-line-init
# Init starship
eval "$(starship init zsh)"
# Pull back to our transient prompt
# We call starship within the prompt function when warranted
PS1='$(_prompt)'