2020-02-14 16:31:52 +01:00
|
|
|
# vim:ft=zsh ts=2 sw=2 sts=2
|
2023-12-21 16:07:52 +01:00
|
|
|
# brethil oh-my-zsh theme
|
|
|
|
# See "EXPANSION OF PROMPT SEQUENCES" in `man zshmisc`
|
|
|
|
# Note: Most of the expansions/color sequences can be tested using `print -P`
|
2020-02-14 16:31:52 +01:00
|
|
|
|
2024-04-09 16:59:12 +02:00
|
|
|
local user='%(!.%K{160}%F{255}%B%n%b%k%f.)' # prints 'root' on a red background if user is root
|
|
|
|
local host='%K{202}%B%F{255}%m%f%k%b' # bold host name on an orange background
|
|
|
|
local open_bracket='%(!.[.)'
|
|
|
|
local close_bracket='%(!.].)'
|
|
|
|
local at='%(!.@.)'
|
|
|
|
local user_prompt
|
|
|
|
if [[ -n $SSH_CONNECTION ]]; then
|
|
|
|
user_prompt="[${user}${at}${host}]"
|
|
|
|
else
|
|
|
|
user_prompt="${open_bracket}${user}${close_bracket}"
|
|
|
|
fi
|
2020-12-04 21:06:59 +01:00
|
|
|
|
2024-04-05 13:08:21 +02:00
|
|
|
local job_prompt="%(1j.%B%K{202}%F{220} %j %k%b.)"
|
2020-12-04 21:06:59 +01:00
|
|
|
|
|
|
|
|
2024-04-09 16:59:12 +02:00
|
|
|
local shlvl_prompt
|
|
|
|
# Shows SHLVL on a magenta background if SHLVL > 1 (2 if in a tmux session)
|
|
|
|
if [[ -z "$TMUX" ]]; then
|
|
|
|
shlvl_prompt="%(2L.%K{161}%F{255}%B %L %f%b%k.)"
|
|
|
|
else
|
|
|
|
shlvl_prompt="%(3L.%K{161}%F{255}%B $((SHLVL-1)) %f%b%k.)"
|
|
|
|
fi
|
|
|
|
|
2024-04-05 13:08:21 +02:00
|
|
|
# Shows last 3 items in path if there are more than 4
|
2024-08-12 18:01:54 +02:00
|
|
|
if [[ -n $DOTFILES_MINIMAL ]]; then
|
|
|
|
local path_prompt='[%F{green}%(4~:…/%3~:%~)%f]'
|
|
|
|
else
|
|
|
|
local path_prompt='[%F{green}%c%f]'
|
|
|
|
fi
|
|
|
|
|
2020-02-14 16:31:52 +01:00
|
|
|
|
|
|
|
# PREFIX/SUFFIX are added before/after `git_prompt_info`
|
2024-04-05 13:08:21 +02:00
|
|
|
ZSH_THEME_GIT_PROMPT_PREFIX=" %f%{$fg[yellow]%} "
|
|
|
|
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} |"
|
2017-06-12 16:22:05 +02:00
|
|
|
|
2024-08-12 17:27:55 +02:00
|
|
|
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}x%{$reset_color%}"
|
|
|
|
ZSH_THEME_GIT_PROMPT_CLEAN=" %{$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]%}="
|
2023-12-21 16:07:52 +01:00
|
|
|
ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE=">"
|
|
|
|
ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="<"
|
|
|
|
ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="<>"
|
2020-02-14 16:31:52 +01:00
|
|
|
|
2024-04-09 16:59:12 +02:00
|
|
|
|
|
|
|
local BOLD_PURPLE='%B%F{5}'
|
|
|
|
local CLEAR='%f%b'
|
|
|
|
local venv
|
2024-08-12 17:27:55 +02:00
|
|
|
function __virtualenv_info {
|
2020-12-04 01:56:14 +01:00
|
|
|
[ -z "$VIRTUAL_ENV" ] && return
|
|
|
|
venv="$(basename "$VIRTUAL_ENV")"
|
|
|
|
if [[ "$venv" == ".venv" ]]; then
|
|
|
|
venv="$(basename $(dirname "$VIRTUAL_ENV") )"
|
|
|
|
fi
|
|
|
|
|
2024-05-09 16:33:31 +02:00
|
|
|
# bold (%B) purple (%F{5})
|
|
|
|
echo -n " %B%F{5}<$venv>%b%f "
|
2020-02-14 16:31:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-05 13:08:21 +02:00
|
|
|
local git_prompt='$(git_prompt_info)$(git_prompt_status)$(git_remote_status)'
|
2020-02-14 16:31:52 +01:00
|
|
|
|
2024-04-05 13:08:21 +02:00
|
|
|
local return_code_RPS1='%(?..%B%F{88}-$?-%f%b)'
|
2023-12-21 16:07:52 +01:00
|
|
|
|
2024-04-05 13:08:21 +02:00
|
|
|
local success="%B%F{28} →%f%b"
|
|
|
|
local failure="%B%{$fg[red]%} x%b%{$reset_color%}"
|
2024-08-12 17:27:55 +02:00
|
|
|
local prompt_with_previous_return_status="%(?:$success:$failure)"
|
2020-12-04 21:06:59 +01:00
|
|
|
|
2024-08-12 17:27:55 +02:00
|
|
|
function __prompt_too_long(){
|
2024-05-09 12:37:39 +02:00
|
|
|
# prints a newline if less than $COLUMNS/2 characters remain to the right margin, see end of `man zshmisc`
|
|
|
|
echo "%-$((COLUMNS/2))(l..\n)"
|
|
|
|
}
|
2024-08-12 17:29:42 +02:00
|
|
|
function __print_prompt_marker(){
|
|
|
|
# prints the escape sequence that tmux interprets as prompt start (see next-prompt/previous-prompt in `man tmux`)
|
|
|
|
printf '\033]133;A\033\\'
|
|
|
|
}
|
2020-12-09 10:53:52 +01:00
|
|
|
|
2023-12-21 16:07:52 +01:00
|
|
|
## oh-my-zsh vi-mode plugins indicators:
|
|
|
|
export MODE_INDICATOR="[%B%K{red}nav%k%b]" # red background
|
|
|
|
export INSERT_MODE_INDICATOR="[%B%K{28}ins%k%b]" # green background
|
|
|
|
|
2024-08-12 17:29:42 +02:00
|
|
|
## put it all together
|
|
|
|
# Note: wrapping __print_prompt_marker in extra %{...%} works around an issue with zsh autosuggestions with escape sequences
|
|
|
|
# see https://github.com/zsh-users/zsh-autosuggestions/issues/570 for more information
|
|
|
|
PROMPT='$(__virtualenv_info)'"${user_prompt}${path_prompt}${git_prompt}${job_prompt}${shlvl_prompt}$(__prompt_too_long)${prompt_with_previous_return_status}%{$(__print_prompt_marker)%} "
|
|
|
|
# right prompt indicator: return code, vi mode prompt info and current time
|
2024-08-12 18:01:54 +02:00
|
|
|
if [[ -z $DOTFILES_MINIMAL ]]; then
|
|
|
|
RPS1="${return_code_RPS1}"'$(vi_mode_prompt_info)[%*]'
|
|
|
|
fi
|