201 lines
5.4 KiB
Bash
201 lines
5.4 KiB
Bash
|
|
_here="$(dirname -- "$(readlink -f -- "${HOME}/.zshrc")")"
|
|
|
|
###########
|
|
# Options #
|
|
###########
|
|
# Ref: https://zsh.sourceforge.io/Doc/Release/Options.html
|
|
|
|
setopt CORRECT
|
|
setopt INTERACTIVE_COMMENTS
|
|
unsetopt NOMATCH
|
|
|
|
# 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
|
|
|
|
###################
|
|
# Shell Variables #
|
|
###################
|
|
# Ref: https://zsh.sourceforge.io/Doc/Release/Parameters.html
|
|
|
|
path=("${HOME}/.local/bin" "${path[@]}")
|
|
fpath=("${_here}/.zsh_functions" "${fpath[@]}")
|
|
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=''
|
|
|
|
############
|
|
# Keybinds #
|
|
############
|
|
|
|
if ! infocmp "$TERM" >/dev/null; then
|
|
echo "TERM $TERM not supported on your system!" >&2
|
|
echo "Some keybindings might not work properly." >&2
|
|
fi
|
|
|
|
if [[ -n $terminfo ]]; then
|
|
# create a zkbd compatible hash;
|
|
# to add other keys to this hash, see: man terminfo 5
|
|
typeset -g -A key
|
|
|
|
key[Home]=${terminfo[khome]}
|
|
key[End]=${terminfo[kend]}
|
|
key[Insert]=${terminfo[kich1]}
|
|
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[CtrlLeft]=${terminfo[kLFT5]}
|
|
key[CtrlRight]=${terminfo[kRIT5]}
|
|
|
|
# Function mapping
|
|
[[ -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[Delete]}" ]] && bindkey "${key[Delete]}" delete-char
|
|
[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" history-beginning-search-backward-end
|
|
[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" history-beginning-search-forward-end
|
|
[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char
|
|
[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char
|
|
[[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" beginning-of-history
|
|
[[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" end-of-history
|
|
[[ -n "${key[CtrlLeft]}" ]] && bindkey "${key[CtrlLeft]}" backward-word
|
|
[[ -n "${key[CtrlRight]}" ]] && bindkey "${key[CtrlRight]}" forward-word
|
|
|
|
bindkey "^R" history-incremental-search-backward
|
|
|
|
# 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
|
|
fi
|
|
|
|
###########
|
|
# Plugins #
|
|
###########
|
|
|
|
if [[ ! -d "${_here}/.cache" ]]; then
|
|
mkdir "${_here}/.cache"
|
|
fi
|
|
|
|
_antidote="${_here}/.cache/.antidote"
|
|
_plugins="${_here}/.zsh_plugins.txt"
|
|
_plugins_cache="${_here}/.cache/.zsh_plugins.zsh"
|
|
|
|
if [[ ! -d "$_antidote" ]]; then
|
|
git clone --depth=1 https://github.com/mattmc3/antidote.git "$_antidote"
|
|
fi
|
|
|
|
if [[ ! -f "${_plugins}" ]]; then
|
|
touch "${_plugins}"
|
|
fi
|
|
|
|
fpath=("${_antidote}/functions" "${fpath[@]}")
|
|
autoload -Uz antidote
|
|
|
|
if [[ ! "${_plugins_cache}" -nt "${_plugins}" ]]; then
|
|
antidote bundle <"${_plugins}" >"${_plugins_cache}"
|
|
fi
|
|
|
|
# shellcheck source=.cache/.zsh_plugins.zsh
|
|
source "${_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 preexec() { set_terminal_title "$1" }
|
|
|
|
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 ln='ln -fi'
|
|
alias rm='rm -I'
|
|
alias n='nnn -dHerU'
|
|
alias ssh='ssh_with_title'
|
|
|
|
##########
|
|
# Prompt #
|
|
##########
|
|
|
|
autoload -Uz promptinit
|
|
promptinit
|
|
prompt warg
|