dotfiles

My dotfiles, nothing really interesting to see ...
git clone https://git.onna.be/dotfiles.git
Log | Files | Refs | README

commit ac90b68fb6027ab77395342f0ef95609ea57b7aa
parent 67c4a3c82a5e94d1d87187fc26367463139fd3d3
Author: Paco Esteban <paco@onna.be>
Date:   Wed, 27 Jun 2018 11:48:53 +0200

new minimalist zsh theme, losely based on agnoster

Diffstat:
zsh/.zsh/theme.zsh | 126+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
zsh/.zshrc | 2+-
2 files changed, 127 insertions(+), 1 deletion(-)

diff --git a/zsh/.zsh/theme.zsh b/zsh/.zsh/theme.zsh @@ -0,0 +1,126 @@ +# enable prompt substitution +setopt PROMPT_SUBST + +DEFAULT_BG="black" +DEFAULT_FG="white" + +# prints block +# accepts text, bg, fg +# if bg or fg ommited defaults +function _prompt_segment () { + local bg fg + [[ -n $2 ]] && bg="%K{$2}" || bg="%k" + [[ -n $3 ]] && fg="%F{$3}" || fg="%f" + [[ -n $1 ]] && \ + print -n "%{$bg%}%{$fg%}$1%{%k%f%}" +} + +function _prompt_end () { + print -n "%{%k%f%}" +} + +function _prompt_separator () { + print -n "%{%K{black}%}%{%F{27}%} : %{%k%f%}" +} + +# vcs +function _prompt_vcs() { + local color ref mod branch + # TODO: make this valid for other vcs + is_dirty() { + test -n "$(git status --porcelain --ignore-submodules)" + } + ref="$vcs_info_msg_0_" + branch=$(echo $sed | sed 's/.*:\(.*\)/\1/') + if [[ -n "$ref" ]]; then + if is_dirty; then + color=yellow + mod="[+]" + else + color=green + mod="[=]" + fi + if [[ ! "${branch/.../}" == "$branch" ]]; then + ref="* ${ref/.../}" + fi + _prompt_separator + _prompt_segment $ref $DEFAULT_BG $DEFAULT_FG + _prompt_segment $mod $DEFAULT_BG $color + fi +} + +function _prompt_context () { + _prompt_segment "$HOST" $DEFAULT_BG $DEFAULT_FG + _prompt_separator +} + +function _prompt_dir() { + _prompt_segment '%~' $DEFAULT_BG $DEFAULT_FG +} + +# Error stats code if any +function _prompt_status() { + if [[ $RETVAL -ne 0 ]]; then + _prompt_segment "[$RETVAL]" $DEFAULT_BG red + _prompt_separator + fi +} + +# Display current virtual environment +function _prompt_virtualenv() { + if [[ -n $VIRTUAL_ENV ]]; then + _prompt_segment "$(basename $VIRTUAL_ENV)" $DEFAULT_BG cyan + _prompt_separator + fi +} + +# Display k8s cluster info if flag is on +function _prompt_k8s() { + if [[ -n $K8S_PROMPT ]]; then + _prompt_segment "$(kube_ps1)" $DEFAULT_BG cyan + _prompt_separator + fi +} + +# Display gcloud info if flag is on +function _prompt_gcloud() { + if [[ -n $GCLOUD_PROMPT ]]; then + _prompt_segment "$(gcloud_active_config)" $DEFAULT_BG cyan + _prompt_separator + fi +} + +# main theme construction +_prompt_main() { + RETVAL=$? + _prompt_status + _prompt_virtualenv + _prompt_k8s + _prompt_gcloud + # _prompt_context + _prompt_dir + _prompt_vcs + _prompt_segment " >" $DEFAULT_BG $DEFAULT_FG + _prompt_end +} + +_prompt_precmd() { + vcs_info + PROMPT='%{%f%b%k%}$(_prompt_main) ' +} + +prompt_theme_setup() { + autoload -Uz add-zsh-hook + autoload -Uz vcs_info + + prompt_opts=(cr subst percent) + + add-zsh-hook precmd _prompt_precmd + + zstyle ':vcs_info:*' enable git + zstyle ':vcs_info:*' check-for-changes false + zstyle ':vcs_info:git*' formats '(%s)%b' + zstyle ':vcs_info:git*' actionformats '%s:%b(%a)' +} + +prompt_theme_setup "$@" diff --git a/zsh/.zshrc b/zsh/.zshrc @@ -37,5 +37,5 @@ bindkey -M vicmd V edit-command-line source $HOME/.zsh/includes.zsh source $HOME/.zsh/aliases.zsh -source $HOME/.zsh/agnoster.zsh-theme +source $HOME/.zsh/theme.zsh [ -f $HOME/.zshenv.local ] && source $HOME/.zshenv.local