dotfiles/zsh/.zshrc

112 lines
3.3 KiB
Bash

# `.zshrc' is sourced in interactive shells. It should contain
# commands to set up aliases, functions, options, key bindings, etc.
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
autoload -U colors && colors
autoload -Uz promptinit && promptinit
autoload -U compinit && compinit
# Init plugin handling
[ -f $HOME/.local/share/miniplug.zsh ] || curl \
-sL --create-dirs \
https://git.sr.ht/~yerinalexey/miniplug/blob/master/miniplug.zsh \
-o $HOME/.local/share/miniplug.zsh
source "$HOME/.local/share/miniplug.zsh"
# Use emacs keybindings even if our EDITOR is set to vi
bindkey -e
bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word
bindkey -s '^L' '^Uclear^M' # clear using alias
autoload edit-command-line; zle -N edit-command-line
bindkey '^k' edit-command-line
# History
HISTORY_IGNORE="(ls|cd|pwd|exit|sudo reboot|history|cd -|cd ..)"
HISTFILE="$HOME/.zsh_history"
HISTSIZE=99999
SAVEHIST=90000
setopt extended_history # record timestamp of command in HISTFILE
setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
setopt hist_ignore_dups # Don't add duplicate entries
setopt hist_ignore_space # ignore commands that start with space
setopt hist_verify # show command with history expansion to user before running it
setopt inc_append_history # add commands to HISTFILE in order of execution
setopt share_history # share command history data
setopt hist_find_no_dups # don't display duplicates in reverse search
setopt hist_reduce_blanks # remove superfluous blanks
setopt interactivecomments # Comments in the interactive shell
setopt auto_continue # Send CONT signal automatically when disowning jobs
# pushd
setopt pushd_ignore_dups
export DIRSTACKSIZE=20
setopt auto_pushd
# Load aliases
source "$HOME/.config/shell_common/aliases.sh"
# zsh-specific aliases
# clear zsh history: Adapted from Novimatrem: https://gitlab.com/Novimatrem/clear-bash-history
alias czh="echo 'Fully clearing history, then exiting...' && cat /dev/null > ${HISTFILE} && history -p && exit"
# Completion
_comp_options+=(globdots) # include hidden files
# reload the zsh session. Changed from OMZ:plugins/zsh_reload
zreload() {
# Use $SHELL if available; remove leading dash if login shell
[[ -n "$SHELL" ]] && exec ${SHELL#-} || exec zsh
}
# Emacs/ vterm
vterm_printf(){
if [ -n "$TMUX" ] && ([ "${TERM%%-*}" = "tmux" ] || [ "${TERM%%-*}" = "screen" ] ); then
# Tell tmux to pass the escape sequences through
printf "\ePtmux;\e\e]%s\007\e\\" "$1"
elif [ "${TERM%%-*}" = "screen" ]; then
# GNU screen (screen, screen-256color, screen-256color-bce)
printf "\eP\e]%s\007\e\\" "$1"
else
printf "\e]%s\e\\" "$1"
fi
}
if [[ "$INSIDE_EMACS" = 'vterm' ]]; then
alias clear='vterm_printf "51;Evterm-clear-scrollback";tput clear'
fi
vterm_cmd() {
local vterm_elisp
vterm_elisp=""
while [ $# -gt 0 ]; do
vterm_elisp="$vterm_elisp""$(printf '"%s" ' "$(printf "%s" "$1" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')")"
shift
done
vterm_printf "51;E$vterm_elisp"
}
find_file() {
vterm_cmd find-file "$(realpath "${@:-.}")"
}
# PLUGINS!
# `miniplug update`
miniplug plugin 'zsh-users/zsh-syntax-highlighting'
miniplug plugin 'hlissner/zsh-autopair'
miniplug theme 'tjquillan/pastel'
miniplug load
# auto cd must be set later
setopt AUTO_CD
# Hooks
eval "$(direnv hook zsh)"