dotfiles/zsh/.zshrc

154 lines
4.6 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
# bindkey -s '^f' '^Ufghq^M' # fghq from alias
# 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 HIST_IGNORE_SPACE # put a space at the front and you won't record history
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
}
# w/ SSH
if [[ "$HOST" == core.envs.net ]]; then
export GPG_TTY=$(tty)
fi
# tycho (which is a laptop)
#if [[ "$HOST" == tycho && -z "$DISPLAY" ]]; then
# export GPG_TTY=$(tty)
#fi
gpgtemp() {
export GPG_TTY=$(tty)
echo "remember to run gpgyeet once done..."
}
# pash configuration
export PASH_KEYID=BF66E5C8A1416E2A857C774CA343F43342EB6E2A
pash() {
case $1 in
g*) # git, not using atm
cd "${PASH_DIR:=${XDG_DATA_HOME:=$HOME/.local/share}/pash}"
shift
git "$@"
;;
sync) # uses rsync, will overwrite to match local
cd "${PASH_DIR:=${XDG_DATA_HOME:=$HOME/.local/share}/pash}"
shift; send_host="$1"; shift
[ -z "$send_host" ] && echo "No destination provided" || \
rsync -ravz --delete . \
"${send_host}:${PASH_DIR:=${XDG_DATA_HOME:=$HOME/.local/share}/pash}" "$@"
;;
*)
command pash "$@"
;;
esac
}
# GPG: invalidate cache
gpgyeet() {
echo RELOADAGENT | gpg-connect-agent
unset GPG_TTY
}
# emacs magit
magit() {
emacs --eval "(progn (magit-status) (delete-other-windows))" "$@"
}
# eye candy: auto onefetch (consider if this is really needed lol)
# https://www.reddit.com/r/unixporn/comments/sxa02o/oc_neofetch_for_git_repositories/
# PLUGINS!
# `miniplug update`
miniplug plugin 'zsh-users/zsh-syntax-highlighting'
miniplug plugin 'hlissner/zsh-autopair'
miniplug theme 'tjquillan/pastel'
miniplug load
export SD_ROOT="$HOME/.dotfiles/.sd"
export SD_CAT=bat
# auto cd must be set later
setopt AUTO_CD
# Hooks
eval "$(direnv hook zsh)"
eval "$(zoxide init zsh)"
if [[ $HOST == "blahaj.local" ]]; then
export PATH="/usr/local/opt/llvm/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"
# -I tells GCC where to look for header files to include
export C_INCLUDE_PATH="${C_INCLUDE_PATH}:/opt/homebrew/include"
export LIBRARY_PATH="${LIBRARY_PATH}:/opt/homebrew/lib"
fi
PATH="/Users/earne/perl5/bin${PATH:+:${PATH}}"; export PATH;
PERL5LIB="/Users/earne/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/Users/earne/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/Users/earne/perl5\""; export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/Users/earne/perl5"; export PERL_MM_OPT;