Files
dotfiles/zsh/rc
T
2024-07-31 11:47:54 +02:00

157 lines
3.1 KiB
Bash

# vim: set ft=zsh:
_here="$(dirname -- "$(readlink -f -- "${HOME}/.zshrc")")"
_cache_dir="${XDG_CACHE_HOME:-"${HOME}/.cache"}/zsh"
if [[ ! -d "${_cache_dir}" ]]; then
mkdir -p "${_cache_dir}"
fi
###########
# Options #
###########
# Ref: https://zsh.sourceforge.io/Doc/Release/Options.html
setopt CORRECT
setopt INTERACTIVE_COMMENTS
unsetopt BEEP
unsetopt NOMATCH
unsetopt FLOW_CONTROL
# History
setopt BANG_HIST
setopt EXTENDED_HISTORY
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_NO_STORE
setopt HIST_REDUCE_BLANKS
setopt HIST_VERIFY
setopt INC_APPEND_HISTORY_TIME
# Emacs mode
bindkey -e
###################
# Shell Variables #
###################
# Ref: https://zsh.sourceforge.io/Doc/Release/Parameters.html
path=("${HOME}/.local/bin" "${path[@]}")
export PATH
export MAIL="/var/spool/mail/$USER"
export MAILCHECK=60
export HISTFILE="${HOME}/.zsh_history"
export HISTSIZE=100100
export SAVEHIST=100000
###################
# Other Variables #
###################
export VISUAL="nvim"
export EDITOR="nvim"
export DIFFPROG="nvim -d"
export NNN_TRASH=2
export NNN_PLUG=''
##########
# Prompt #
##########
source "${_here}/prompt"
###########
# Plugins #
###########
_antidote="${_cache_dir}/antidote"
_plugins="${_here}/plugins"
_plugins_cache="${_cache_dir}/plugins"
if [[ ! -d "$_antidote" ]]; then
git clone --depth=1 https://github.com/mattmc3/antidote.git "$_antidote"
fi
fpath=("${_antidote}/functions" "${fpath[@]}")
autoload -Uz antidote
if [[ ! "${_plugins_cache}" -nt "${_plugins}" ]]; then
antidote bundle <"${_plugins}" >"${_plugins_cache}"
fi
# shellcheck disable=SC1090
source "${_plugins_cache}"
unset _antidote _plugins _plugins_cache
#############
# Functions #
#############
# Ref: https://zsh.sourceforge.io/Doc/Release/Functions.html#Functions
function set_terminal_title() {
local title
if [ -z "$1" ]; then
title=$(basename "$(print -P "%~")")
else
title="$1"
fi
echo -ne "\033]2;$title\033\\"
}
function precmd() {
set_terminal_title
}
function ssh_with_title() {
local host=""
local skip_next="false"
for arg in "$@"; do
case "$arg" in
-[bcDeFIiLlmOopRSWw]?*)
# Option with argument immediately after, like -p22
skip_next="false"
;;
-[bcDeFIiLlmOopRSWw])
# Option with argument on next iteration
skip_next="true"
;;
-*)
# Any other option, assumed not to take an argument
skip_next="false"
;;
*)
if [ "$skip_next" = "true" ]; then
skip_next="false"
else
host="${arg#*@}"
fi
;;
esac
done
set_terminal_title "$host"
ssh "$@"
set_terminal_title
}
###########
# Aliases #
###########
alias cp='cp -i'
alias ln='ln -fi'
alias ls='ls --color=auto --group-directories-first -vh'
alias mv='mv -i'
alias n='nnn -dHerU'
alias rm='rm -I'
alias ssh='ssh_with_title'
###########
# Cleanup #
###########
unset _here _cache_dir