dotfiles/dot_zshrc.tmpl
2024-05-10 20:16:26 +08:00

192 lines
5.4 KiB
Cheetah

autoload -Uz compinit
compinit
# autocompletion with an arrow-key driven interface
zstyle ':completion:*' menu select
# 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
# history search
autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
[[ -n "${key[Up]}" ]] && bindkey -- "${key[Up]}" up-line-or-beginning-search
[[ -n "${key[Down]}" ]] && bindkey -- "${key[Down]}" down-line-or-beginning-search
# shift, alt, tab and mod modifiers
key[Control-Left]="${terminfo[kLFT5]}"
key[Control-Right]="${terminfo[kRIT5]}"
[[ -n "${key[Control-Left]}" ]] && bindkey -- "${key[Control-Left]}" backward-word
[[ -n "${key[Control-Right]}" ]] && bindkey -- "${key[Control-Right]}" forward-word
# custom PATH
path+=("$HOME"'/.local/bin')
path+=("$HOME"'/.cargo/bin')
# export to sub-processes (make it inherited by child processes)
export PATH
# homebrew config
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh
source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# micromamba
if command -v micromamba &> /dev/null; then
export MAMBA_EXE=$(which micromamba);
export MAMBA_ROOT_PREFIX='~/.micromamba';
__mamba_setup="$("$MAMBA_EXE" shell hook --shell zsh --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__mamba_setup"
else
alias micromamba="$MAMBA_EXE" # Fallback on help from mamba activate
fi
unset __mamba_setup
fi
# starship config
if command -v starship &> /dev/null; then
eval "$(starship init zsh)"
fi
# fnm config
if command -v fnm &> /dev/null; then
eval "$(fnm env --use-on-cd)"
fi
# thefuck config
fuck() {
unfunction fuck
eval $(thefuck --alias)
fuck "$@"
}
# yazi config
function ya() {
local tmp="$(mktemp -t "yazi-cwd.XXXXX")"
yazi "$@" --cwd-file="$tmp"
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
cd -- "$cwd"
fi
rm -f -- "$tmp"
}
# atuin config
if command -v atuin &> /dev/null; then
eval "$(atuin init zsh --disable-up-arrow)"
fi
# zoxide config
if command -v zoxide &> /dev/null; then
eval "$(zoxide init zsh)"
fi
# nix config
if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]; then . $HOME/.nix-profile/etc/profile.d/nix.sh; fi # added by Nix installer
# editors
export EDITOR="nano"
export VISUAL="code"
# sops keys
export SOPS_AGE_RECIPIENTS="op://Private/Age/public key"
export SOPS_AGE_KEY="op://Private/Age/private key"
# custome alias
# alias code=code-insiders
alias ..='cd ..'
alias ...='cd ../..'
alias ls=eza
alias tree='eza --tree'
alias f=fuck
alias v=nvim
alias sops='op run --no-masking -- sops'
alias dotfiles='chezmoi'
alias ze='zellij'
# micromamba|conda alias
alias mm='micromamba'
alias ma='micromamba activate'
alias mda='micromamba activate base'
alias mc='micromamba create'
alias mr='micromamba run'
alias mi='micromamba install'
alias ml='micromamba list'
alias me='micromamba env'
alias mel='micromamba env list'
alias conda='micromamba'
# git alias
alias g='git'
alias ga='git add'
alias gb='git branch'
alias gc='git commit'
alias gcm='git commit -m'
alias gcl='git clone --recurse-submodules'
alias gl='git pull'
alias gp='git push'
# distrobox alias
alias box='distrobox'
alias i='cd ~/i'
{{if eq .chezmoi.os "windows" -}}
# windows spec config
{{- else if eq .chezmoi.os "linux" -}}
{{- if (.chezmoi.kernel.osrelease | lower | contains "microsoft") -}}
# wsl spec config
alias ssh="ssh.exe"
{{- else -}}
# linux spec config
{{- end -}}
{{- end}}