Files
dotfiles/zsh/zshrc
2023-07-12 06:01:34 -04:00

98 lines
3.4 KiB
Bash

# Bring "xterm" up to "xterm-256color", fairly well expected this should work
[[ "$TERM" == "xterm" ]] && export TERM="xterm-256color"
# Make sure that p10k.zsh is in place, otherwise link it from dotfiles repo
if [[ ! -a "$HOME/.p10k.zsh" ]]; then
DOTFILES_ZSH_DIR="$(dirname "$(readlink -f "$HOME/.zshrc")")"
if [[ -a "${DOTFILES_ZSH_DIR}/p10k.zsh" ]]; then
ln -s "${DOTFILES_ZSH_DIR}/p10k.zsh" "$HOME/.p10k.zsh"
fi
fi
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# make sure antigen exists
if [[ ! -a ~/.antigen.zsh ]]; then
wget https://git.io/antigen -O ~/.antigen.zsh
fi
# Add .local/bin
if [[ ! "$PATH" =~ "$HOME/.local/bin" ]]; then
export PATH="$HOME/.local/bin:$PATH"
fi
# powerlevel9k config
POWERLEVEL9K_INSTALLATION_PATH=$ANTIGEN_BUNDLES/bhilburn/powerlevel9k
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status root_indicator context dir virtualenv vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(background_jobs)
POWERLEVEL9K_STATUS_OK=false
POWERLEVEL9K_VIRTUALENV_BACKGROUND=028
# load in antigen
source ~/.antigen.zsh
# pull in oh-my-zsh
antigen use oh-my-zsh
# plugins from oh-my-zsh
antigen bundle git
# plugins from other repos
antigen bundle zsh-users/zsh-autosuggestions
antigen bundle zsh-users/zsh-syntax-highlighting
# set the theme
#antigen theme agnoster
antigen theme romkatv/powerlevel10k
# finish up
antigen apply
# zsh autosuggestions
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
# Preferred Editor
export EDITOR="vim"
# commands aliases
alias svim="sudoedit"
alias unlock="gpg -o /dev/null -s /dev/null"
function dotfiles-update() {
pushd "$(dirname "$(dirname "$(readlink -f "$HOME/.zshrc")")")" >> /dev/null
git pull
popd >> /dev/null
}
function context-color() {
hexcount=$(($(infocmp -1 | sed -n -e 's/^\t*colors#\([0-9]x\?[0-9]*\),.*/\1/p')-1))
hash=$(hostname | sum | cut -d' ' -f1)
excludes="0,7,15"
id=$(( $hash % $hexcount ))
for excid in $(echo "$excludes" | tr "," '\n'); do
if [ "$id" -ge "$excid" ]; then
id=$((id + 1))
fi
done
echo $id
}
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs direnv asdf virtualenv anaconda pyenv goenv nodenv nvm nodeenv rbenv rvm fvm luaenv jenv plenv perlbrew phpenv scalaenv haskell_stack kubecontext terraform aws aws_eb_env azure gcloud google_app_cred toolbox newline context prompt_char)
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status command_execution_time background_jobs ranger nnn lf xplr vim_shell midnight_commander nix_shell chezmoi_shell todo timewarrior taskwarrior time newline load ram swap battery)
typeset -g POWERLEVEL9K_MODE=powerline
typeset -g POWERLEVEL9K_ICON_PADDING=none
typeset -g POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
typeset -g POWERLEVEL9K_CONTEXT_PREFIX=
typeset -g POWERLEVEL9K_CONTEXT_DEFAULT_BACKGROUND=$(context-color)
typeset -g POWERLEVEL9K_CONTEXT_REMOTE_BACKGROUND=$(context-color)
typeset -g POWERLEVEL9K_CONTEXT_DEFAULT_FOREGROUND=15
typeset -g POWERLEVEL9K_CONTEXT_REMOTE_FOREGROUND=15