autoload -Uz promptinit && promptinit
+function tool_versions() {
+ if [[ -s ".tool-versions" ]]; then
+ echo '.tool-versions'
+ return
+ fi
+ echo "${HOME}/.tool-versions"
+}
+
if [[ "$TERM" == (dumb|linux|*bsd*) ]] || (( $#prompt_argv < 1 )); then
prompt 'off'
fi
#
-# Precmd
+# Functions
#
-function prompt_precmd {
- git-info
+function env_info_provider() { echo "%{%F{green}%}n/a"; }
+function env_info {
+ echo "[%{%F{cyan}%}ENV%{%F{black}%} $(env_info_provider)%{%F{black}%}]"
}
-#
-# Functions
-#
+function python_info {
+ pythoninfo=`cat "$(tool_versions)" | rg python | cut -d ' ' -f 2`
+ pythoninfo=${ASDF_PYTHON_VERSION:-$pythoninfo}
+ venv="${VIRTUAL_ENV##*/}"
+ echo "%{%F{green}%}py%{%F{black}%} ${pythoninfo:-no}@${venv:-default}"
+}
-function virtualenv_info {
- if [[ -z "$VIRTUAL_ENV" ]]; then
- venv="default"
- else
- venv="${VIRTUAL_ENV##*/}"
- fi
- echo "🐍${venv}"
+function rust_info {
+ rustinfo=`cat "$(tool_versions)" | rg rust | cut -d ' ' -f 2`
+ rustinfo=${ASDF_RUST_VERSION:-$rustinfo}
+ echo "%{%F{red}%}rs%{%F{black}%} ${rustinfo:-no}"
}
-function rvm_info {
- if [[ -z "$RUBY_VERSION" ]]; then
- rvminfo="default"
- else
- rvminfo=`rvm-prompt`
- fi
- echo "💎${rvminfo}"
+function node_info {
+ nodeinfo=`cat "$(tool_versions)" | rg nodejs | cut -d ' ' -f 2`
+ nodeinfo=${ASDF_NODEJS_VERSION:-$nodeinfo}
+ echo "%{%F{yellow}%}js%{%F{black}%} ${nodeinfo:-no}"
}
-function nvm_info {
- if [[ -z "$NVM_BIN" ]]; then
- nvminfo="default"
- else
- nvminfo=`nvm current`
+function git_info {
+ branch=$(git branch --show-current 2> /dev/null)
+
+ if [ ! -z $branch ]; then
+ echo -n "@%F{cyan}$branch%f"
+
+ status_output=$(git status --short)
+
+ if echo "$status_output" | grep -q '^??'; then
+ echo -n "%{%F{magenta}%}?%f"
+ fi
+
+ if echo "$status_output" | grep -q '^ M'; then
+ echo -n "%{%F{magenta}%}!%f"
+ fi
+
+ if echo "$status_output" | grep -q '^ D'; then
+ echo -n "%{%F{magenta}%}×%f"
+ fi
+
+ if echo "$status_output" | grep -q '^A '; then
+ echo -n "%{%F{green}%}+%f"
+ fi
fi
- echo "💛${nvminfo}"
}
function box_name {
#
function zle-line-init zle-keymap-select {
- local return_status="%{%F{red}%}%(?..🆇)%{$reset_color%}"
+
+ # Couldn't figure out how to get tmux and iTerm to agree on how to render
+ # these characters... so there you go.
+
+ local normal_symbol="N"
+ local insert_symbol="I"
+ local error_symbol="X"
+
+ # Show vi status / return status on the right side
+
+ local return_status="%{%F{red}%}%(?.. $error_symbol)%{$reset_color%}"
if [ $KEYMAP = 'vicmd' ]; then
- local edit_status="%{%F{cyan}%}🅽"
+ local edit_status="%{%F{cyan}%}$normal_symbol"
else
- local edit_status="%{%F{green}%}🅸"
+ local edit_status="%{%F{green}%}$insert_symbol"
fi
- RPS1="${edit_status} ${return_status}%{$reset_color%}"
- RPS2=$RPS1
+ RPROMPT="${edit_status}${return_status}%{$reset_color%}"
zle reset-prompt
}
zle -N zle-line-init
# 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%} )$ '
+%{%F{black}%}$(env_info) $(node_info) $(rust_info) $(python_info)
+%{%F{magenta}%}%n%{%f%}@%{%F{yellow}%}$(box_name)%{%f%} %{%B%F{green}%}${PWD/#$HOME/~}%{%f%b%}$(git_info)%{%f%}
+%(?,,%{${%B%F{white}%}[%?]%{%f%b%} )%% '
}
prompt_setup "$@"
setopt PROMPT_SUBST
+setopt PROMPT_PERCENT
+setopt TRANSIENT_RPROMPT