dotfiles/executable_dot_zshrc
2024-08-21 12:34:13 -04:00

173 lines
5.6 KiB
Bash

#!/bin/zsh
# Runs for interactive shells
checkCommand(){
type "$1" >/dev/null 2>&1
}
# Set aliases
[ -f "$HOME/.aliasrc" ] && source "$HOME/.aliasrc" # >/dev/null 2>&1 &;
# Speed up shell load on WSL
OLDPATH=$PATH
PATH=$(echo "$PATH" | sed -e 's/\/mnt\/.*\?://g')
# Uncomment to debug lag
#zmodload zsh/zprof
# Set where history is saved and how much to save
HISTFILE="$XDG_STATE_HOME/zsh/history"
[ ! -e $HISTFILE ] && mkdir -p "$XDG_STATE_HOME/zsh" && touch $HISTFILE
HISTSIZE=10000
SAVEHIST=$HISTSIZE
HISTDUP=erase
# disable system beep on error
setopt BEEP
# if you type a folder name, it will automatically cd into it
setopt autocd
# if a glob has no matches, display an error
setopt nomatch
# report status of bg jobs immediately
setopt notify
#dedupe history, and append to histfile after every command
setopt hist_find_no_dups hist_save_no_dups hist_ignore_dups appendhistory sharehistory
# vim style line editing
bindkey -v
# make file name completion case-insensitive
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
zstyle ':completion:*' cache-path $XDG_CACHE_HOME/zsh/zcompcache
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' menu no
zstyle 'fzf-tab:complete:cd:*' fzf-preview `ls $realpath`
zstyle 'fzf-tab:complete:__zoxide_z:*' fzf-preview `ls $realpath`
# Move completions to XDG Dir
autoload -Uz compinit
compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-"$ZSH_VERSION"
# Use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
HYPHEN_INSENSITIVE="true"
# Display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"
# Speed up autosuggestions
ZSH_AUTOSUGGEST_MANUAL_REBIND="true"
# fix home end and delete buttons
# create a zkbd compatible hash;
# to add other keys to this hash, see: man 5 terminfo
typeset -g -A key
key[Home]="${terminfo[khome]}"
key[End]="${terminfo[kend]}"
key[Insert]="${terminfo[kich1]}"
key[Backspace]="${terminfo[kbs]}"
key[Delete]="${terminfo[kdch1]}"
key[Up]="${terminfo[kcuu1]}"
key[Down]="${terminfo[kcud1]}"
key[Left]="${terminfo[kcub1]}"
key[Right]="${terminfo[kcuf1]}"
key[PageUp]="${terminfo[kpp]}"
key[PageDown]="${terminfo[knp]}"
key[Shift-Tab]="${terminfo[kcbt]}"
# setup key accordingly
[[ -n "${key[Home]}" ]] && bindkey -- "${key[Home]}" beginning-of-line
[[ -n "${key[End]}" ]] && bindkey -- "${key[End]}" end-of-line
[[ -n "${key[Insert]}" ]] && bindkey -- "${key[Insert]}" overwrite-mode
[[ -n "${key[Backspace]}" ]] && bindkey -- "${key[Backspace]}" backward-delete-char
[[ -n "${key[Delete]}" ]] && bindkey -- "${key[Delete]}" delete-char
[[ -n "${key[Up]}" ]] && bindkey -- "${key[Up]}" up-line-or-history
[[ -n "${key[Down]}" ]] && bindkey -- "${key[Down]}" down-line-or-history
[[ -n "${key[Left]}" ]] && bindkey -- "${key[Left]}" backward-char
[[ -n "${key[Right]}" ]] && bindkey -- "${key[Right]}" forward-char
[[ -n "${key[PageUp]}" ]] && bindkey -- "${key[PageUp]}" beginning-of-buffer-or-history
[[ -n "${key[PageDown]}" ]] && bindkey -- "${key[PageDown]}" end-of-buffer-or-history
[[ -n "${key[Shift-Tab]}" ]] && bindkey -- "${key[Shift-Tab]}" reverse-menu-complete
# Finally, make sure the terminal is in application mode, when zle is
# active. Only then are the values from $terminfo valid.
if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
autoload -Uz add-zle-hook-widget
function zle_application_mode_start { echoti smkx }
function zle_application_mode_stop { echoti rmkx }
add-zle-hook-widget -Uz zle-line-init zle_application_mode_start
add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop
fi
#Allows fuzzy-finding
if checkCommand fzf; then
export FZF_BASE=$(which fzf)
fi
#todo: install if not found
# Load plugins
if checkCommand sheldon; then
mkdir -p ~/.config/sheldon
touch ~/.config/sheldon/plugins.toml
eval "$(sheldon -q source)";
fi
# if ssh-agent isn't running, run it
if ! pgrep -u "$USER" '(ssh|gpg)-agent' >/dev/null; then
if checkCommand gpg-agent; then
gpg-agent --daemon --enable-ssh-support >> "$HOME/.ssh-agent.env";
unset SSH_AGENT_PID;
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-socket);
export GPG_TTY=$(tty)
gpg-connect-agent updatestartuptty /bye >/dev/null
elif checkCommand ssh-agent; then
ssh-agent > "$HOME/.ssh-agent.env";
fi
fi
if [ ! -f "$SSH_AUTH_SOCK" ] && [ -f ~/.ssh-agent.env ]; then
source "$HOME/.ssh-agent.env" >/dev/null
fi
# Set up mcfly if installed (lets you search through history easily with ctrl+r)
if checkCommand mcfly; then
export MCFLY_KEY_SCHEME=vim
export MCFLY_FUZZY=2
eval "$(mcfly init zsh)"
fi
# set up zoxide if installed (lets you jump through folders easily using the z and zi commands instead of cd)
if checkCommand zoxide; then
eval "$(zoxide init zsh)"
fi
# if checkCommand direnv; then
# eval "$(direnv hook zsh)"
# fi
if checkCommand yazi; then
function yy() {
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")"
yazi "$@" --cwd-file="$tmp"
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
cd -- "$cwd"
fi
rm -f -- "$tmp"
}
fi
if checkCommand mirafetch; then
RUST_BACKTRACE=1 mirafetch
fi
PATH=$OLDPATH
unset OLDPATH
checkCommand starship && eval "$(starship init zsh)"
# TODO: move these
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# bun completions
[ -s "/home/akristip/.bun/_bun" ] && source "/home/akristip/.bun/_bun"
# bun
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"