2020-02-14 16:31:52 +01:00
|
|
|
|
# vim:ft=zsh ts=2 sw=2 sts=2
|
|
|
|
|
# color chart available at https://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html
|
|
|
|
|
# %F{202}: orange
|
|
|
|
|
# %K{202}: background orange
|
|
|
|
|
# 255: white
|
|
|
|
|
# See the prompt expansion section in `info zsh` for more info
|
|
|
|
|
|
2020-12-04 21:06:59 +01:00
|
|
|
|
function user_prompt(){
|
2021-03-13 14:50:57 +01:00
|
|
|
|
# prints info about username/hostname
|
|
|
|
|
# for ssh connections
|
|
|
|
|
local p
|
|
|
|
|
local host
|
|
|
|
|
if [[ $UID -eq 0 ]]; then
|
|
|
|
|
# root
|
|
|
|
|
echo -n "%F{255}[%f" # open square bracket
|
|
|
|
|
echo -n "%K{160}%F{255}%Broot%b%k%f"
|
|
|
|
|
if [[ $SSH_CONNECTION ]]; then
|
|
|
|
|
# add the white @
|
|
|
|
|
# echo -n '%F{255} at %f'
|
|
|
|
|
echo -n "%F{255}@%f"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
if [[ $SSH_CONNECTION ]]; then
|
|
|
|
|
if [[ $UID -ne 0 ]]; then
|
|
|
|
|
echo -n "%F{255}[%f" # open square bracket
|
|
|
|
|
fi
|
|
|
|
|
# underlined orange hostname (%m)
|
|
|
|
|
echo -n "%K{202}%B%F{255}%m%f%k%b"
|
|
|
|
|
if [[ $UID -ne 0 ]]; then
|
|
|
|
|
echo -n "%F{255}]%f" # close square bracket
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
# close square bracket
|
|
|
|
|
if [[ $UID -eq 0 ]]; then echo "%F{255}]%f"; fi
|
2020-12-04 21:06:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function job_prompt() {
|
|
|
|
|
local JOB_PROMPT="%(1j.%B%K{202}%F{220} %j %k%b.)" # Shows jobs number on an orange background if there are background jobs
|
|
|
|
|
echo "$JOB_PROMPT"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function shlvl_prompt() {
|
|
|
|
|
local SHLVL_PROMPT
|
|
|
|
|
if [[ -n "$BYOBU_PREFIX" ]]; then
|
|
|
|
|
SHLVL_PROMPT="%(3L.%K{161}%F{255}%B $((SHLVL-1)) %f%b%k.)" # Shows SHLVL on a magenta background if SHLVL > 1
|
|
|
|
|
else
|
|
|
|
|
SHLVL_PROMPT="%(2L.%K{161}%F{255}%B %L %f%b%k.)" # Shows SHLVL on a magenta background if SHLVL > 1
|
|
|
|
|
fi
|
|
|
|
|
echo "$SHLVL_PROMPT"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function path_prompt(){
|
|
|
|
|
# Shows last 3 items in path if there are more than 4
|
|
|
|
|
local PATH_PROMPT="%F{white}[%F{green}%(4~:…/%3~:%~)%F{white}]%f"
|
|
|
|
|
echo "$PATH_PROMPT"
|
|
|
|
|
}
|
2020-02-14 16:31:52 +01:00
|
|
|
|
|
|
|
|
|
# PREFIX/SUFFIX are added before/after `git_prompt_info`
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_PREFIX="%f%{$fg[yellow]%} "
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
|
2017-06-12 16:22:05 +02:00
|
|
|
|
|
2020-12-04 02:52:15 +01:00
|
|
|
|
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[white]%}%{$fg[red]%}x%{$reset_color%}"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[white]%}%{$fg[green]%}√%{$reset_color%}"
|
2020-02-14 16:31:52 +01:00
|
|
|
|
|
|
|
|
|
# The following are part of `git_prompt_status`
|
|
|
|
|
# Rules:
|
|
|
|
|
# ? : untracked
|
|
|
|
|
# * : modified
|
|
|
|
|
# + : added
|
|
|
|
|
# $ : stashed
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_STASHED="%B%F{32}$%b%f" # blue
|
2020-12-04 02:52:15 +01:00
|
|
|
|
# ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[red]%}✗ " # this is equivalent to DIRTY, if DISABLE_UNTRACKED_FILES_DIRTY is set
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_ADDED="%B%F{34}+%b%f" # green
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_UNTRACKED="%B%F{red}?%b%f" # red
|
2020-02-14 16:31:52 +01:00
|
|
|
|
|
|
|
|
|
# The following are part of `git_remote_status`
|
|
|
|
|
# ZSH_THEME_GIT_PROMPT_EQUAL_REMOTE="%{$fg[green]%}="
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE="%F{255}>%f"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="%F{255}<%f"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="%F{255}<>%f"
|
|
|
|
|
|
|
|
|
|
function virtualenv_info {
|
2020-12-04 01:56:14 +01:00
|
|
|
|
[ -z "$VIRTUAL_ENV" ] && return
|
|
|
|
|
|
|
|
|
|
local BOLD_PURPLE='%B%F{5}'
|
|
|
|
|
local CLEAR='%f%b'
|
|
|
|
|
local venv
|
|
|
|
|
venv="$(basename "$VIRTUAL_ENV")"
|
|
|
|
|
if [[ "$venv" == ".venv" ]]; then
|
|
|
|
|
venv="$(basename $(dirname "$VIRTUAL_ENV") )"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo -n "$BOLD_PURPLE"
|
|
|
|
|
echo -n " <$venv> "
|
|
|
|
|
echo -n "$CLEAR"
|
2020-02-14 16:31:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function git_prompt() {
|
|
|
|
|
if [[ -n "$(git status 2>/dev/null)" ]]; then
|
2021-01-09 23:53:54 +01:00
|
|
|
|
local GIT_PROMPT=" %F{255}$(git_prompt_info)%B%F{255} |%f%b$(git_prompt_status)$(git_remote_status)"
|
2020-02-14 16:31:52 +01:00
|
|
|
|
echo "$GIT_PROMPT"
|
|
|
|
|
else
|
|
|
|
|
echo ""
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function check_last_exit_code() {
|
|
|
|
|
local LAST_EXIT_CODE=$?
|
|
|
|
|
if [[ $LAST_EXIT_CODE -ne 0 ]]; then
|
2020-12-04 21:06:59 +01:00
|
|
|
|
local EXIT_CODE_PROMPT
|
2020-02-14 16:31:52 +01:00
|
|
|
|
EXIT_CODE_PROMPT+="%B%F{88}-$LAST_EXIT_CODE-%f%b"
|
|
|
|
|
echo "$EXIT_CODE_PROMPT"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-04 21:06:59 +01:00
|
|
|
|
function return_code_RPS1() {
|
|
|
|
|
# For right-side prompt
|
|
|
|
|
local return_code="%(?..$(check_last_exit_code))" # for RPS1
|
|
|
|
|
echo "$return_code"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ret_status() {
|
|
|
|
|
local ret_status="%(?:%B%F{28} →%f%b:%{$fg[red]%} x%{$reset_color%})"
|
|
|
|
|
echo "$ret_status"
|
|
|
|
|
}
|
2020-02-14 16:31:52 +01:00
|
|
|
|
|
2021-03-13 15:27:06 +01:00
|
|
|
|
export MODE_INDICATOR="[%B%K{88}nav%k%b]"
|
|
|
|
|
# export INSERT_MODE_INDICATOR="[%B%K{28}ins%k%b]"
|
2021-01-15 01:34:10 +01:00
|
|
|
|
|
2021-02-21 23:48:58 +01:00
|
|
|
|
_PROMPT_PROTO='$(virtualenv_info)$(user_prompt)$(path_prompt)$(git_prompt)$(job_prompt)$(shlvl_prompt)'
|
2020-12-04 21:06:59 +01:00
|
|
|
|
|
|
|
|
|
function prompt_too_long(){
|
|
|
|
|
local zero='%([BSUbfksu]|([FK]|){*})'
|
2020-12-09 10:53:52 +01:00
|
|
|
|
if [[ -x $commands[gsed] ]]; then # fuck darwin
|
|
|
|
|
sed='gsed'
|
|
|
|
|
elif [[ "$(uname)" == "Darwin" ]]; then
|
|
|
|
|
local msg="error: multi-line prompt requires GNU sed"
|
|
|
|
|
msg+="install with \"brew install gnu-sed\""
|
|
|
|
|
echo "$msg"
|
|
|
|
|
return
|
|
|
|
|
else
|
|
|
|
|
sed='sed'
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
local stripped="$(echo ${(S%%)_PROMPT_PROTO//$~zero/} | $sed 's|\x1B\[[0-9;]*[a-zA-Z]||g')"
|
2020-12-04 21:06:59 +01:00
|
|
|
|
local prompt_len=${#stripped}
|
|
|
|
|
local max_len=$(($COLUMNS/2))
|
|
|
|
|
if [[ $prompt_len -ge $max_len ]]; then
|
|
|
|
|
echo true
|
|
|
|
|
fi
|
|
|
|
|
}
|
2020-12-09 10:53:52 +01:00
|
|
|
|
|
2020-12-04 21:06:59 +01:00
|
|
|
|
PROMPT="$(echo "$_PROMPT_PROTO")"
|
|
|
|
|
NEWLINE=$'\n'
|
|
|
|
|
PROMPT+='${$(prompt_too_long)/true/${NEWLINE}}'
|
|
|
|
|
PROMPT+='$(ret_status) '
|
2020-02-14 16:31:52 +01:00
|
|
|
|
|
|
|
|
|
# Right prompt is just return code and time
|
2021-02-21 23:48:58 +01:00
|
|
|
|
RPS1='$(return_code_RPS1)$(vi_mode_prompt_info)%F{255}[%*]%f'
|