mirror of
https://git.decapod.one/brethil/dotfiles
synced 2024-11-22 11:31:30 +01:00
114 lines
3.5 KiB
Bash
114 lines
3.5 KiB
Bash
# vim:ft=zsh ts=2 sw=2 sts=2
|
|
# 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`
|
|
|
|
function user_prompt(){
|
|
# prints hostname on an orange background if on an ssh connection, adds username if root
|
|
|
|
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='%(!.@.)'
|
|
if [[ -n $SSH_CONNECTION ]]; then
|
|
echo "[${user}${at}${host}]"
|
|
else
|
|
echo "${open_bracket}${user}${close_bracket}"
|
|
fi
|
|
}
|
|
|
|
function job_prompt() {
|
|
# Shows jobs number on an orange background if there are background jobs
|
|
echo "%(1j.%B%K{202}%F{220} %j %k%b.)"
|
|
}
|
|
|
|
function shlvl_prompt() {
|
|
# Shows SHLVL on a magenta background if SHLVL > 1 (2 if in a tmux session)
|
|
if [[ -z "$TMUX" ]]; then
|
|
echo "%(2L.%K{161}%F{255}%B %L %f%b%k.)"
|
|
else
|
|
echo "%(3L.%K{161}%F{255}%B $((SHLVL-1)) %f%b%k.)"
|
|
fi
|
|
}
|
|
|
|
function path_prompt(){
|
|
# Shows last 3 items in path if there are more than 4
|
|
echo "[%F{green}%(4~:…/%3~:%~)%f]"
|
|
}
|
|
|
|
# PREFIX/SUFFIX are added before/after `git_prompt_info`
|
|
ZSH_THEME_GIT_PROMPT_PREFIX="%f%{$fg[yellow]%} "
|
|
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
|
|
|
|
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[white]%}%{$fg[red]%}x%{$reset_color%}"
|
|
ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[white]%}%{$fg[green]%}√%{$reset_color%}"
|
|
|
|
# The following are part of `git_prompt_status`
|
|
# Rules:
|
|
# ? : untracked
|
|
# * : modified
|
|
# + : added
|
|
# $ : stashed
|
|
ZSH_THEME_GIT_PROMPT_STASHED="%B%F{32}$%b%f" # blue
|
|
# 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
|
|
|
|
# The following are part of `git_remote_status`
|
|
# ZSH_THEME_GIT_PROMPT_EQUAL_REMOTE="%{$fg[green]%}="
|
|
ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE=">"
|
|
ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="<"
|
|
ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="<>"
|
|
|
|
function virtualenv_info {
|
|
[ -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<$venv>$CLEAR "
|
|
}
|
|
|
|
function git_prompt() {
|
|
# prints git info if in a git repo
|
|
if ! git rev-parse --git-dir &>/dev/null; then
|
|
return
|
|
fi
|
|
|
|
echo " $(git_prompt_info) |$(git_prompt_status)$(git_remote_status)"
|
|
}
|
|
|
|
|
|
function return_code_RPS1() {
|
|
# red status code if last exit code is non-zero
|
|
echo "%(?..%B%F{88}-$?-%f%b)"
|
|
}
|
|
|
|
function prompt_with_previous_return_status() {
|
|
local success="%B%F{28} →%f%b"
|
|
local failure="%B%{$fg[red]%} x%b%{$reset_color%}"
|
|
echo "%(?:$success:$failure)"
|
|
}
|
|
|
|
|
|
function prompt_too_long(){
|
|
# prints a newline if more than $COLUMNS/2 characters have been printed
|
|
local newline=$'\n'
|
|
echo "%-$((COLUMNS/2))(l..${newline})"
|
|
}
|
|
|
|
## 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
|
|
|
|
PROMPT='$(virtualenv_info)$(user_prompt)$(path_prompt)$(git_prompt)$(job_prompt)$(shlvl_prompt)$(prompt_too_long)$(prompt_with_previous_return_status) '
|
|
|
|
# Right prompt is just return code and time
|
|
RPS1='$(return_code_RPS1)$(vi_mode_prompt_info)[%*]'
|