dotfiles/.zshrc

248 lines
6.3 KiB
Bash
Raw Normal View History

if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit"
command git clone --depth=1 https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \
print -P "%F{33} %F{34}Installation successful.%f%b" || \
print -P "%F{160} The clone has failed.%f%b"
fi
2022-02-15 23:36:54 +01:00
source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
2018-04-04 17:37:05 +02:00
2022-09-12 09:53:21 +02:00
zi ice wait lucid
zi load zsh-users/zsh-completions
zi ice wait lucid
zi load zsh-users/zsh-syntax-highlighting
zi ice wait lucid
zi load zsh-users/zsh-history-substring-search
2018-04-04 17:37:05 +02:00
2020-09-27 16:38:35 +02:00
## History
HISTSIZE=50000
SAVEHIST=50000
HISTFILE=~/.zsh_history
setopt append_history
setopt extended_history
setopt hist_expire_dups_first
setopt hist_fcntl_lock
setopt hist_ignore_all_dups
setopt hist_ignore_space
setopt HIST_IGNORE_SPACE
setopt hist_lex_words
setopt hist_reduce_blanks
setopt hist_save_no_dups
setopt hist_subst_pattern
setopt hist_verify
setopt share_history
2022-08-31 09:18:44 +02:00
export HISTORY_IGNORE="(ls *|cd *|rm *|pwd|reboot|exit|e *|*AWS*|*SECRET*|*PASSWORD*|*TOKEN*|*API*|*KEY*|*PASS*|*SECRETS*|*SECRET_KEY*|*SECRET_TOKEN*|*SECRET_KEY_BASE*|*SECRET_TOKEN_BASE*)"
2020-09-27 16:38:35 +02:00
## zsh settings
setopt pipe_fail
setopt auto_pushd
setopt no_beep
setopt no_rm_star_silent
setopt extended_glob
setopt ksh_glob
setopt null_glob
2020-09-28 17:05:15 +02:00
## Autosuggest
2020-09-28 23:16:07 +02:00
# ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#D7CCC8,italic"
# ZSH_AUTOSUGGEST_USE_ASYNC=1
# ZSH_AUTOSUGGEST_STRATEGY=(history completion)
2022-03-19 13:44:04 +01:00
export PATH=$HOME/bin:$PATH
2020-09-28 23:16:07 +02:00
redraw-prompt() {
local precmd
for precmd in $precmd_functions; do
$precmd
done
zle reset-prompt
}
zle -N redraw-prompt
_jump() {
2022-08-30 14:47:41 +02:00
_dir=$(fre --sorted | fzf-tmux --no-sort -p 90%,40% -y 0)
[ -n "$_dir" ] && pushd $_dir >>/dev/null
2020-09-28 23:16:07 +02:00
zle && zle redraw-prompt
}
zle -N _jump
2020-09-28 17:05:15 +02:00
fre_chpwd() {
fre --add "$(pwd)"
}
typeset -gaU chpwd_functions
chpwd_functions+=fre_chpwd
_cwd_gitroot() {
_gitroot=$(git rev-parse --show-toplevel 2>/dev/null || sl root 2>/dev/null || pwd)
2022-08-30 14:47:41 +02:00
_dir=$((echo "$_gitroot" && fd -td . "$_gitroot") | fzf-tmux -p 90%,40% -y 0)
[ -n "$_dir" ] && cd $_dir
zle && zle redraw-prompt
}
zle -N _cwd_gitroot
2020-09-27 16:38:35 +02:00
## Keybindings
bindkey -e
2020-10-19 12:20:28 +02:00
bindkey '^[[A' history-beginning-search-backward
bindkey '^[[B' history-beginning-search-forward
2020-09-28 23:16:07 +02:00
bindkey '^P' history-beginning-search-backward
bindkey '^N' history-beginning-search-forward
bindkey '^g' _jump
bindkey '^_' _cwd_gitroot
2020-09-27 16:38:35 +02:00
2020-09-27 13:56:54 +02:00
## Gnupg / gpg / ssh / yubikey
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
2019-12-04 17:28:14 +01:00
2020-04-22 08:30:34 +02:00
## Pager
2020-11-15 14:30:52 +01:00
export LESS="--mouse --wheel-lines=1 -nRXF"
2021-06-19 11:55:31 +02:00
## Clipboard OSC 52
function clip { echo -en "\x1b]52;c;$(base64 -w0)\x07" }
2020-09-27 13:56:54 +02:00
## Aliases
2021-06-19 11:55:31 +02:00
alias c='cut -c-${COLUMNS}'
2022-08-30 14:47:41 +02:00
alias e='tmux-edit-helper'
2020-09-27 13:56:54 +02:00
alias dotgit='git --work-tree $HOME --git-dir $HOME/.dot_git'
2020-09-28 17:05:15 +02:00
alias l=bat
2022-09-30 09:50:36 +02:00
alias lw='bat --wrap=never'
2019-10-19 12:36:29 +02:00
alias ls=exa
2020-09-27 13:56:54 +02:00
alias tail='tail -n $LINES'
alias timestamp='TZ=Z date "+%Y%m%dT%H%M%SZ"'
alias tree='exa --tree'
2020-11-15 14:30:52 +01:00
alias v=vgrep
alias ve='env EDITOR= vgrep -s'
2021-06-19 11:55:31 +02:00
alias xc=clip
2022-07-12 13:47:33 +02:00
alias w="history -1 | sed -e 's/[0-9]* //' | xargs viddy -n1"
2018-01-17 21:38:11 +01:00
2022-03-19 15:41:33 +01:00
## ripgrep
export RIPGREP_CONFIG_PATH=${HOME}/.config/rg/rg.conf
# "auto paging"
rg() {
/usr/bin/rg -p "$@" | bat
}
2020-11-15 14:30:52 +01:00
2022-11-22 09:55:14 +01:00
fix_cursor() {
echo -ne '\e[5 q'
}
precmd_functions+=(fix_cursor)
2021-04-02 17:31:47 +02:00
## Prompt
eval "$(starship init zsh)"
2018-01-03 08:47:21 +01:00
## vim
2020-09-27 13:56:54 +02:00
export EDITOR=nvim
2018-01-03 08:47:21 +01:00
2020-09-28 13:43:50 +02:00
## fzf
export FZF_TMUX=1
export FZF_COMPLETION_TRIGGER=";"
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
. /usr/share/fzf/completion.zsh
. /usr/share/fzf/key-bindings.zsh
2020-09-05 13:20:38 +02:00
## direnv
eval "$(direnv hook zsh)"
2022-08-25 10:10:44 +02:00
## pyenv
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
export PATH="/home/dln/.pyenv/shims:${PATH}"
export PYENV_SHELL=zsh
# command pyenv rehash 2>/dev/null # this is slow
pyenv() {
local command
command="${1:-}"
if [ "$#" -gt 0 ]; then
shift
fi
case "$command" in
activate|deactivate|rehash|shell)
eval "$(pyenv "sh-$command" "$@")"
;;
*)
command pyenv "$command" "$@"
;;
esac
}
2022-08-25 10:10:44 +02:00
2022-04-16 14:47:28 +02:00
## eksctl
if [ ! -f "${fpath[1]}/_eksctl" ]; then
command -v eksctl >/dev/null 2>&1 && eksctl completion zsh > "${fpath[1]}/_eksctl"
fi
2020-09-27 13:56:54 +02:00
## Kubernetes
if [ ! -f "${fpath[1]}/_kubectl" ]; then
command -v kubectl >/dev/null 2>&1 && kubectl completion zsh > "${fpath[1]}/_kubectl"
fi
2019-12-02 11:30:13 +01:00
export PATH=$HOME/.krew/bin:$PATH
2022-07-17 09:36:48 +02:00
## bazel
if [ ! -f "${fpath[1]}/_bazel" ]; then
curl -sLo "${fpath[1]}/_bazel" https://raw.githubusercontent.com/bazelbuild/bazel/master/scripts/zsh_completion/_bazel
2021-07-22 10:32:46 +02:00
fi
2019-10-19 12:36:29 +02:00
2023-01-26 22:24:42 +01:00
## sapling
if [ ! -f "${fpath[1]}/_sl" ]; then
# See: https://github.com/facebook/sapling/pull/369
curl -sLo "${fpath[1]}/_sl" https://github.com/facebook/sapling/raw/d6157db1ebc0868cf70805756e32541bd681bac2/eden/scm/contrib/zsh_completion_sl
fi
2021-04-15 14:40:05 +02:00
## Tekton cli
2021-07-22 10:32:46 +02:00
if [ ! -f "${fpath[1]}/_tkn" ]; then
command -v tkn >/dev/null 2>&1 && tkn completion zsh > "${fpath[1]}/_tkn"
fi
2021-04-15 14:40:05 +02:00
2021-06-17 11:29:04 +02:00
## kapp
2021-07-22 10:32:46 +02:00
if [ ! -f "${fpath[1]}/_kapp" ]; then
command -v kapp >/dev/null 2>&1 && kapp completion zsh --tty=false > "${fpath[1]}/_kapp"
fi
2021-06-17 11:29:04 +02:00
2022-03-19 13:44:04 +01:00
## kn
if [ ! -f "${fpath[1]}/_kn" ]; then
command -v kn >/dev/null 2>&1 && kn completion zsh > "${fpath[1]}/_kn"
fi
2021-06-17 11:29:04 +02:00
## talos cli
2021-07-22 10:32:46 +02:00
if [ ! -f "${fpath[1]}/_talosctl" ]; then
command -v talosctl >/dev/null 2>&1 && talosctl completion zsh > "${fpath[1]}/_talosctl"
fi
2021-06-17 11:29:04 +02:00
2020-09-27 13:56:54 +02:00
## Google Cloud
2017-08-09 08:43:48 +02:00
[ -f /opt/google-cloud-sdk/completion.zsh.inc ] && source /opt/google-cloud-sdk/completion.zsh.inc
2021-01-03 13:16:07 +01:00
2019-09-03 14:50:36 +02:00
## Golang
2020-09-27 13:56:54 +02:00
export PATH=$HOME/go/bin:$PATH
2021-07-22 10:32:46 +02:00
GOPROXY=https://athens.aarn.shelman.io
2019-09-03 14:50:36 +02:00
## Ansible
export ANSIBLE_NOCOWS=1
2019-01-01 19:48:52 +01:00
2021-07-22 10:32:46 +02:00
## Docker
export DOCKER_BUILDKIT=1
2023-01-26 22:24:53 +01:00
autoload -Uz compinit
compinit
autoload -Uz compdef
2022-06-07 09:46:36 +02:00
PROG=tea _CLI_ZSH_AUTOCOMPLETE_HACK=1 source "/home/dln/.config/tea/autocomplete.zsh"
2022-07-17 09:36:48 +02:00
2022-11-22 09:56:09 +01:00
## AWS
2022-07-17 09:36:48 +02:00
autoload -U +X bashcompinit && bashcompinit
complete -o nospace -C /usr/bin/mcli mcli
2022-09-30 09:50:36 +02:00
complete -C '/usr/bin/aws_completer' aws
2022-10-07 10:27:10 +02:00
2022-09-30 09:50:36 +02:00
# The next line updates PATH for the Google Cloud SDK.
2022-10-07 10:27:10 +02:00
if [ -f '/home/dln/google-cloud-sdk/path.zsh.inc' ]; then . '/home/dln/google-cloud-sdk/path.zsh.inc'; fi
2022-09-30 09:50:36 +02:00
# The next line enables shell command completion for gcloud.
2022-10-07 10:27:10 +02:00
if [ -f '/home/dln/google-cloud-sdk/completion.zsh.inc' ]; then . '/home/dln/google-cloud-sdk/completion.zsh.inc'; fi