[ $DEBUG_DOTFILES ] && echo "Loading .zshrc" # Load initialization [ $DEBUG_DOTFILES ] && echo " Loading ~/.config/shell/init" source ~/.config/shell/init # load the sourcesfile, which in turn will source more functionality [ $DEBUG_DOTFILES ] && echo " Loading ~/.config/shell/sources" source ~/.config/shell/sources # autoload compontents {{{ [ $DEBUG_DOTFILES ] && echo " Autoloading components" autoload -U colors && colors autoload -U compinit && compinit autoload -U promptinit && promptinit # }}} # set base options {{{ [ $DEBUG_DOTFILES ] && echo " Setting base options" setopt appendhistory autocd autopushd extendedglob histignorespace prompt_subst vi unsetopt beep nomatch notify # }}} # vi mode [ $DEBUG_DOTFILES ] && echo " Setting vi-mode" bindkey -v # Extend vi mode with some happy good vim stuff function zle-move-to-buffer-beginning { CURSOR=0 } zle -N zle-move-to-buffer-beginning # zsh apparently doesn't read inputrc, so fix some "special" keys manually 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]}" [[ -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 # Bind some emacs-style bindings in insert mode bindkey -M viins '^a' beginning-of-line bindkey -M viins '^b' backward-char bindkey -M viins '^e' end-of-line bindkey -M viins '^f' forward-char bindkey -M viins '^k' kill-line bindkey -M viins '^n' history-beginning-search-forward bindkey -M viins '^p' history-beginning-search-backward bindkey -M viins '^u' kill-region bindkey -M viins '^y' yank # Bind the vim bindings bindkey -M vicmd "gg" zle-move-to-buffer-beginning # configure components {{{ [ $DEBUG_DOTFILES ] && echo " Setting autocompletions" zstyle :compinstall filename '/home/tyil/.zshrc' zstyle ':completion:*' menu select # Enable comments in interactive zsh set -k # }}} function precmd() # {{{ { # format the last command's exitcode EXITCODE=$(printf "%03i" "$?") # set window title echo -en "\e]2;`whoami`@`hostname -f`:`pwd`\a" # git info {{{ if git rev-parse --is-inside-work-tree &> /dev/null then # Set coloring of the branch name if [ "$(git status -uno --porcelain 2> /dev/null)" = "" ] then GITBRANCHC="%F{2}" else GITBRANCHC="%F{3}" fi # Get the branch name GITBRANCH=$(git rev-parse --abbrev-ref HEAD) if [ "$GITBRANCH" = "HEAD" ] then GITBRANCH=$(git rev-parse --short HEAD 2> /dev/null) fi # Set the prompt PGIT="%F{8}·%f${GITBRANCHC}${GITBRANCH}%f%F{8}" else # Not in a git repo, set a regular prompt PGIT="%F{8}" fi # }}} # set hostname color depending on local or remote connection {{{ HOSTNAME_COLOR="%F{5}" case "$(ps -o comm= -p $PPID)" in sshd|*/sshd|mosh*) HOSTNAME_COLOR="%F{6}" ;; esac # }}} } # }}} # setup vi-mode indicators {{{ VIMODE_I="%F{8}" VIMODE_N="%B%F{3}" VIMODE_U="%B%F{1}" # }}} # set vimode coloring {{{ local vi_mode="$VIMODE_I" vi_mode_indicator () { case ${KEYMAP} in (vicmd) echo $VIMODE_N ;; (main|viins) echo $VIMODE_I ;; (*) echo $VIMODE_U ;; esac } # }}} # reset mode-marker and prompt whenever the keymap changes {{{ function zle-line-init zle-keymap-select { vi_mode="$(vi_mode_indicator)" zle reset-prompt } zle -N zle-line-init zle -N zle-keymap-select # }}} # set the final prompt [ $DEBUG_DOTFILES ] && echo " Setting PS1" PROMPT='%(!.%F{1}.%F{2})%n%F{8}' PROMPT=$PROMPT'@' PROMPT=$PROMPT'${HOSTNAME_COLOR}%M%F{8}' PROMPT=$PROMPT':' PROMPT=$PROMPT'%F{4}%~%k${PGIT}' PROMPT=$PROMPT' ' PROMPT=$PROMPT'%(?.%F{7}.%F{1})${EXITCODE}%k' PROMPT=$PROMPT' ${vi_mode}»%b %f${CURSOR_STYLE}' [ $DEBUG_DOTFILES ] && echo " Enable gpg-agent" gpg-connect-agent /bye export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket) # Apply bundles if [[ -d "${XDG_CONFIG_DIR:-"${HOME}/.config"}/shell/vendor/zsh" ]] then pushd "${XDG_CONFIG_DIR:-"${HOME}/.config"}/shell/vendor/zsh" > /dev/null sources=( "feature-syntax-highlighting/zsh-syntax-highlighting.zsh" ) for bundle in "${sources[@]}" do [[ ! -f "$bundle" ]] && continue source "$bundle" done popd > /dev/null fi autoload -U +X bashcompinit && bashcompinit complete -o nospace -C /usr/bin/terraform terraform