X-Git-Url: https://git.r.bdr.sh/rbdr/dotfiles/blobdiff_plain/f6272d88eae76c8553f237f3f318c4a97997f262..fa25023586cb94a1abf4fd3ff95ebe7c3c8ead09:/zsh/modules/prompt.zsh diff --git a/zsh/modules/prompt.zsh b/zsh/modules/prompt.zsh new file mode 100644 index 0000000..945d9eb --- /dev/null +++ b/zsh/modules/prompt.zsh @@ -0,0 +1,102 @@ +autoload -Uz promptinit && promptinit + +if [[ "$TERM" == (dumb|linux|*bsd*) ]] || (( $#prompt_argv < 1 )); then + prompt 'off' +fi + +# +# Precmd +# + +function prompt_precmd { + git-info +} + +# +# Functions +# + +function virtualenv_info { + if [[ -z "$VIRTUAL_ENV" ]]; then + venv="default" + else + venv="${VIRTUAL_ENV##*/}" + fi + echo "🐍${venv}" +} + +function rvm_info { + if [[ -z "$RUBY_VERSION" ]]; then + rvminfo="default" + else + rvminfo=`rvm-prompt` + fi + echo "💎${rvminfo}" +} + +function nvm_info { + if [[ -z "$NVM_BIN" ]]; then + nvminfo="default" + else + nvminfo=`nvm current` + fi + echo "💛${nvminfo}" +} + +function box_name { + [ -f ~/.box-name ] && cat ~/.box-name || hostname -s +} + +# +# ZLE widgets +# + +function zle-line-init zle-keymap-select { + local return_status="%{%F{red}%}%(?..🆇)%{$reset_color%}" + if [ $KEYMAP = 'vicmd' ]; then + local edit_status="%{%F{cyan}%}🅽" + else + local edit_status="%{%F{green}%}🅸" + fi + + RPS1="${edit_status} ${return_status}%{$reset_color%}" + RPS2=$RPS1 + zle reset-prompt +} +zle -N zle-line-init +zle -N zle-keymap-select + +# +# Setup Prompt +# + +function prompt_setup { + setopt LOCAL_OPTIONS + unsetopt XTRACE KSH_ARRAYS + prompt_opts=(cr percent subst) + + # Load required functions. + autoload -Uz add-zsh-hook + + # Add hook for calling git-info before each command. + add-zsh-hook precmd prompt_precmd + + # Set git-info parameters. + zstyle ':git:info' verbose 'no' + zstyle ':git:info:branch' format '@%F{cyan}%b%f' + zstyle ':git:info:clean' format '' + zstyle ':git:info:added' format '%{%F{green}%}!' + zstyle ':git:info:modified' format '%{%F{green}%}?' + zstyle ':git:info:untracked' format '%{%F{magenta}%}?' + zstyle ':git:info:keys' format \ + 'prompt' '%b%a%m%u' + + # Define prompts. + PROMPT=' +%{%F{black}%}$(nvm_info) $(rvm_info) $(virtualenv_info) +%{%F{magenta}%}%n%{%f%}@%{%F{yellow}%}$(box_name)%{%f%} %{%B%F{green}%}${PWD/#$HOME/~}%{%f%b%}${git_info[prompt]} %{%f%} +%(?,,%{${%B%F{white}%}[%?]%{%f%b%} )$ ' +} + +prompt_setup "$@" +setopt PROMPT_SUBST