profile/home/dotfiles/zshrc

152 lines
3.6 KiB
Bash

#!/bin/zsh
ZSH_DEBUG="${ZSH_DEBUG:-0}"
ZSH_ALIAS=${ZSH_ALIAS:-1}
ZSH_DEFAULT_TERM=${ZSH_DEFAULT_TERM:-1}
ZSH_GPG_PINENTRY_FIX=${ZSH_GPG_PINENTRY_FIX:-1}
ZSH_POWERLINE="${ZSH_POWERLINE:-1}"
ZSH_PRINT_REBOOT_REQUIRED=${ZSH_PRINT_REBOOT_REQUIRED:-0} # hacky, see below
ZSH_SYNTAX_HIGHLIGHTING="${ZSH_SYNTAX_HIGHLIGHTING:-1}"
ZSH_THEFUCK=${ZSH_THEFUCK:-1}
ZSH_DEBUG_SECTION_START_PREFIX="\\ "
ZSH_DEBUG_INDENT="${ZSH_DEBUG_INDENT:- |}"
ZSH_DEBUG_SECTION_END_TEXT="/"
DEBUG_INDENT=0
section() {
if [ $ZSH_DEBUG -gt 0 ]; then
echo "${ZSH_DEBUG_SECTION_START_PREFIX}$(tput smso)$*$(tput rmso)"
fi
(( DEBUG_INDENT++ ))
}
section_end() {
if [ $ZSH_DEBUG -gt 0 ]; then
echo "$ZSH_DEBUG_SECTION_END_TEXT"
fi
(( DEBUG_INDENT-- ))
}
log() {
if [ $ZSH_DEBUG -gt 0 ]; then
indent=""
if [ $DEBUG_INDENT -gt 0 ]; then
for i in $(seq 0 $(( DEBUG_INDENT-1 )) ); do
indent+="$ZSH_DEBUG_INDENT"
done
fi
echo "$*" | while IFS=$'\n' read line; do
echo "$indent" "$line"
done
fi
}
# Powerline
section "powerline"
if [ $ZSH_POWERLINE -gt 0 ]; then
log "Running powerline daemon..."
log "$(powerline-daemon 2>&1)"
log "Finding powerline..."
POWERLINE_DIR="$(pip3 show powerline-status --isolated | grep '^Location:' | awk '{print $2}')"
log "Powerline repository root: $POWERLINE_DIR"
log "Preparing zstyle..."
autoload -Uz promptinit
promptinit
prompt off
log "Loading powerline zsh plugin..."
source "$POWERLINE_DIR/powerline/bindings/zsh/powerline.zsh"
#prompt -s powerline
fi
section_end
# zsh-syntax-highlighting
section "zsh-syntax-highlighting"
if [ $ZSH_SYNTAX_HIGHLIGHTING -gt 0 ]; then
log "Loading plugin..."
if [ -f "/usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" ]; then
source "/usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
else
source "/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
fi
fi
section_end
section "thefuck"
if [ $ZSH_THEFUCK -gt 0 ]; then
eval "$(thefuck --alias)"
fi
section_end
# Default terminal
section "term"
if [ $ZSH_DEFAULT_TERM -gt 0 ] && [ -z "$TERM" ]; then
export TERM=linux
fi
section_end
# gpg password via console
section "gpg pinentry fix"
if [ $ZSH_GPG_PINENTRY_FIX -gt 0 ]; then
log "Changing GPG_TTY to: $(tty)"
GPG_TTY=$(tty)
export GPG_TTY
if [ ! -z "$SSH_CONNECTION" ]; then
log "Detected SSH connection, making pinentry use curses instead of x11."
export PINENTRY_USER_DATA="USE_CURSES=1"
else
log "All good with pinentry itself it seems."
fi
fi
section_end
# alias
section "alias"
if [ $ZSH_ALIAS -gt 0 ]; then
alias ssh-seidemannweb="ssh seiaufjt@cloud3-vm449.de-nserver.de"
alias ssh-pidashboard="ssh -p 10022 -L 5900:localhost:5900 ck@remote.seidemann.com"
alias docker-pidashboard="DOCKER_CERT_PATH=~/.docker/sw-pi-dashboard docker -H tcp://192.168.100.225:2375 --tlsverify"
alias docker-home="docker -H tcp://172.20.3.34:2375"
alias docker-winsrv2016-a="docker -H tcp://vm-winsrv2016-a:2375 --tlsverify"
alias wttr="curl -H 'Accept-Language: de' wttr.in/Reutlingen"
swproject() {
dir=$(find $HOME/src/gitlab.seidemann-web.com -type d -path "*/$1" -and -not -path '*/\.*' -print -quit)
if [ -z "$dir" ]; then
echo "Could not find project directory for $1." >&2
return 1
fi
cd "$dir" || exit 1
return 0
}
export swproject
fi
section_end
# Reboot required? (hacky code)
section "reboot required?"
if [ $ZSH_PRINT_REBOOT_REQUIRED -gt 0 ]; then
if [ "$(pacman -Q linux | cut -d " " -f 2)" -gt "$(uname -r | sed 's,-zen,,' | sed 's,-lts,,')" ]; then
echo "$(tput setaf 1)$(tput bold)Reboot required!"
fi
fi
section_end
# print env
section "Environment variables"
log "$(export)"
section_end