dotfiles/zsh/.zshrc

112 lines
3.3 KiB
Bash
Raw Normal View History

2021-11-04 23:18:36 -04:00
# `.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
2021-11-22 09:58:57 -05:00
[ -f $HOME/.local/share/miniplug.zsh ] || curl \
2021-11-04 23:18:36 -04:00
-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"
2021-11-04 23:18:36 -04:00
# Completion
_comp_options+=(globdots) # include hidden files
2021-12-11 22:24:06 -05:00
# reload the zsh session. Changed from OMZ:plugins/zsh_reload
2021-11-04 23:18:36 -04:00
zreload() {
2021-12-11 22:24:06 -05:00
# 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
}
2021-11-04 23:18:36 -04:00
2021-12-11 22:24:06 -05:00
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
2021-11-04 23:18:36 -04:00
done
2021-12-11 22:24:06 -05:00
vterm_printf "51;E$vterm_elisp"
}
2021-11-04 23:18:36 -04:00
2021-12-11 22:24:06 -05:00
find_file() {
vterm_cmd find-file "$(realpath "${@:-.}")"
2021-11-04 23:18:36 -04:00
}
# 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)"