personal-dotfiles/.zshrc

169 lines
4.5 KiB
Bash

#!/usr/bin/env zsh
### Moony's Zsh config. ###
# CLI colors
RED='\033[91m'
GRN='\033[92m'
YLW='\033[93m'
BLU='\033[94m'
MGA='\033[95m'
CYN='\033[96m'
BLD='\033[1m'
RST='\033[0m'
# Load SSH keys and start agent.
load-our-ssh-keys() {
if [ -z "$SSH_AUTH_SOCK" ]; then
# Check for a currently running instance of the agent.
RUNNING_AGENT="$(ps -ax | grep 'ssh-agent -s' | grep -v grep | wc -l | tr -d '[:space:]')"
if [ "$RUNNING_AGENT" = "0" ]; then
if [ ! -d ~/.ssh ] ; then
mkdir -p ~/.ssh
fi
# Launch a new instance of the agent.
ssh-agent -s &> ~/.ssh/ssh-agent
fi
eval $(cat ~/.ssh/ssh-agent)
fi
# Fun with SSH.
if [ $(ssh-add -l | grep -c "The agent has no identities." ) -eq 1 ]; then
for key in $(find ~/.ssh -type f -a \( -name '*id_rsa' -o -name '*id_dsa' -o -name '*id_ecdsa' -o -name '*id_ed25519' \))
do
if [ -f ${key} -a $(ssh-add -l | grep -F -c "$(ssh-keygen -l -f $key | awk '{print $2}')" ) -eq 0 ]; then
if ( which keychain &> /dev/null ); then
keychain ${key} &> /dev/null
else
ssh-add ${key} &> /dev/null
fi
fi
done
if ( which keychain &> /dev/null ); then
if [[ -r ~/.keychain/$(hostname)-sh ]]; then
source ~/.keychain/$(hostname)-sh
fi
fi
fi
}
if [[ -z "$SSH_CLIENT" ]]; then
# We're not on a remote machine, so load keys
load-our-ssh-keys
fi
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
# General options.
setopt notify
setopt autopushd
# History options.
HISTSIZE=100000
SAVEHIST=100000
HISTFILE=${HISTFILE:-$ZDOTDIR/.zhistory}
setopt share_history
setopt hist_ignore_dups
setopt hist_ignore_space
# Enable menu completion.
# autoload -U compinit && compinit
autoload -Uz compinit
compinit
zstyle ':completion:*' menu select
zstyle ':completion::complete:*' gain-priveleges 1
# Fix Shift-Tab in the completions menu
# bindkey '^[[Z' reverse-menu-complete
# function _zle_line_init() {
# [[ $TERM == rxvt-unicode || $TERM == xterm || $TERM = xterm-256color || $TERM = screen || $TERM == screen-256color ]] && printf '\e[?2004h'
# }
#
# function _zle_line_finish() {
# [[ $TERM == rxvt-unicode || $TERM == xterm || $TERM = xterm-256color || $TERM = screen || $TERM == screen-256color ]] && printf '\e[?2004l'
# }
# Load Zgenom for plugin management.
if [[ -f ${HOME}/.zgenom/zgenom.zsh ]]; then
source ${HOME}/.zgenom/zgenom.zsh
else
git clone https://github.com/jandamm/zgenom.git "${HOME}/.zgenom"
fi
if ! zgenom saved; then
echo -e "${BLD}${YLW}[${BLU}*${YLW}]${RST} Creating a zsh save point..."
zgenom compdef
zgenom ohmyzsh
zgenom ohmyzsh plugins/asdf
zgenom ohmyzsh plugins/colored-man-pages
zgenom ohmyzsh plugins/docker
zgenom ohmyzsh plugins/docker-machine
zgenom ohmyzsh plugins/extract
zgenom ohmyzsh plugins/git
zgenom ohmyzsh plugins/pipenv
# zgenom ohmyzsh plugins/pyenv
zgenom ohmyzsh plugins/sudo
zgenom ohmyzsh plugins/transfer
zgenom ohmyzsh plugins/vagrant
zgenom ohmyzsh plugins/virtualenvwrapper
zgenom ohmyzsh plugins/wd
zgenom prezto editor key-bindings 'emacs'
zgenom load mafredri/zsh-async
zgenom load MichaelAquilina/zsh-auto-notify
zgenom load zpm-zsh/colorize
zgenom load zsh-users/zsh-syntax-highlighting
zgenom load zsh-users/zsh-completions src
zgenom load zsh-users/zsh-autosuggestions
zgenom load zsh-users/zsh-history-substring-search
zgenom load romkatv/powerlevel10k powerlevel10k
zgenom save
zgenom compile $ZDOTDIR/.zshrc
fi
# Load grc aliases.
if [[ -f /etc/grc.zsh ]]; then
source /etc/grc.zsh
fi
# Set the PATH environment variable.
if [[ -f ${HOME}/.zsh/paths.zsh ]]; then
source ${HOME}/.zsh/paths.zsh
fi
# Load custom aliases.
if [[ -f ${HOME}/.zsh/aliases.zsh ]]; then
source ${HOME}/.zsh/aliases.zsh
fi
# Load pentesting aliases.
if [[ -f ${HOME}/.zsh/pentest.zsh ]]; then
source ${HOME}/.zsh/pentest.zsh
fi
# Activate virtual environment management script.
if [[ -f /usr/local/bin/virtualenvwrapper.sh ]]; then
source /usr/local/bin/virtualenvwrapper.sh
fi
# Activate pyenv virtual environment manager.
# eval "$(pyenv virtualenv-init -)"
if [[ -f /opt/asdf-vm/asdf.sh ]]; then
source /opt/asdf-vm/asdf.sh
fi
# Check for tmux and set TERM variable.
[[ -z "$TMUX" ]] && export TERM="xterm-256color"
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
(( ! ${+functions[p10k]} )) || p10k finalize