Skip to content

Instantly share code, notes, and snippets.

@ivangabriele
Last active August 22, 2022 02:49
Show Gist options
  • Save ivangabriele/4633453fdaee3fa498718acd71e42c07 to your computer and use it in GitHub Desktop.
Save ivangabriele/4633453fdaee3fa498718acd71e42c07 to your computer and use it in GitHub Desktop.
My custom Oh My Zsh Theme.
################################################################################
# Oh My Zsh Ivan Theme
# ------------------------------------------------------------------------------
# Constants
local _COLOR_BLUE="%{$fg[blue]%}"
local _COLOR_BLUE_BOLD="%{$fg_bold[blue]%}"
local _COLOR_CYAN="%{$fg[cyan]%}"
local _COLOR_CYAN_BOLD="%{$fg_bold[cyan]%}"
local _COLOR_GREEN="%{$fg[green]%}"
local _COLOR_GREEN_BOLD="%{$fg_bold[green]%}"
local _COLOR_GREY="%{$fg[grey]%}"
local _COLOR_GREY_BOLD="%{$fg_bold[grey]%}"
local _COLOR_MAGENTA="%{$fg[magenta]%}"
local _COLOR_MAGENTA_BOLD="%{$fg_bold[magenta]%}"
local _COLOR_RED="%{$fg[red]%}"
local _COLOR_RED_BOLD="%{$fg_bold[red]%}"
local _COLOR_RESET="%{$reset_color%}"
local _COLOR_YELLOW="%{$fg[yellow]%}"
local _COLOR_YELLOW_BOLD="%{$fg_bold[yellow]%}"
SPACER_CHARACTER="-"
# ------------------------------------------------------------------------------
# Helpers
local get_string_length() {
local string=$1
echo ${#string}
}
local print_spacer () {
local start_string=$1
local end_string=$2
local merged_string="${1}${2}"
local zero='%([BSUbfksu]|([FB]|){*})'
local merged_string_length=${#${(S%%)merged_string//$~zero/}}
local spacer_length=$((COLUMNS - merged_string_length - ${ZLE_RPROMPT_INDENT:-1} - 1))
(( spacer_length > 0 )) || return
printf "${SPACER_CHARACTER}%.0s" {1..$spacer_length}
}
local print_header () {
local header_start="${_COLOR_CYAN}%~${_COLOR_RESET} ${_COLOR_YELLOW_BOLD}$(git_prompt_status)${_COLOR_RESET}"
local header_end="$(git_prompt_info)"
local header_end_length=`get_string_length $header_end`
local header_space=`print_spacer $header_start $header_end`
local header_space_length=`get_string_length $header_space`
local git_branch=$(git_prompt_info)
print
if [[ $header_end_length -gt 0 ]]; then
if [[ header_space_length -gt 0 ]]; then
print -Pr "${header_start}${_COLOR_GREY}${header_space}${_COLOR_RESET} ${header_end}"
else
print -Pr "${header_start}${_COLOR_GREY}"
print -Pr "${header_end}"
fi
else
print -Pr "${header_start}${_COLOR_GREY}${header_space}${SPACER_CHARACTER}${_COLOR_RESET}"
fi
}
# ------------------------------------------------------------------------------
# Git
ZSH_THEME_GIT_PROMPT_PREFIX="${_COLOR_BLUE_BOLD}[git:"
ZSH_THEME_GIT_PROMPT_SUFFIX="]${_COLOR_RESET}"
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_DIRTY=""
ZSH_THEME_GIT_PROMPT_ADDED="(✚) "
ZSH_THEME_GIT_PROMPT_DELETED="(✖) "
ZSH_THEME_GIT_PROMPT_MODIFIED="(✹) "
ZSH_THEME_GIT_PROMPT_RENAMED="(➜) "
ZSH_THEME_GIT_PROMPT_UNMERGED="(═) "
ZSH_THEME_GIT_PROMPT_UNTRACKED="(✭) "
# ------------------------------------------------------------------------------
# Template
local _BODY_START="${_COLOR_YELLOW_BOLD}➞${_COLOR_RESET}"
local _BODY_END="${_COLOR_GREEN}%D{%H:%M:%S}${_COLOR_RESET}"
setopt prompt_subst
PROMPT="${_BODY_START} "
RPROMPT="${_BODY_END}"
# ------------------------------------------------------------------------------
# Load
autoload -U add-zsh-hook
add-zsh-hook precmd print_header
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment