Skip to content

Instantly share code, notes, and snippets.

@eugenk
Last active May 10, 2024 10:43
Show Gist options
  • Save eugenk/1b87f04e37f365fa1fb29551befed0fb to your computer and use it in GitHub Desktop.
Save eugenk/1b87f04e37f365fa1fb29551befed0fb to your computer and use it in GitHub Desktop.
ZSH prompt: Powerlevel9k config
# nerd-font patched (complete) font required! See
# https://github.com/ryanoasis/nerd-fonts
# Set the right locale to protect special characters
POWERLEVEL9K_MODE='nerdfont-complete'
POWERLEVEL9K_VCS_GIT_ICON='\uF1D3'
POWERLEVEL9K_LEFT_SEGMENT_SEPARATOR='\uE0B8'
POWERLEVEL9K_RIGHT_SEGMENT_SEPARATOR='\uE0B6'
POWERLEVEL9K_LEFT_SUBSEGMENT_SEPARATOR='\uE0B1'
POWERLEVEL9K_RIGHT_SUBSEGMENT_SEPARATOR='\uE0B3'
POWERLEVEL9K_BATTERY_CHARGING_FOREGROUND='yellow'
POWERLEVEL9K_BATTERY_CHARGED_FOREGROUND='green'
POWERLEVEL9K_BATTERY_DISCONNECTED_FOREGROUND=013
POWERLEVEL9K_BATTERY_LOW_THRESHOLD=10
POWERLEVEL9K_BATTERY_LOW_FOREGROUND=009
POWERLEVEL9K_BATTERY_ICON='\uF1E6'
POWERLEVEL9K_PROMPT_ON_NEWLINE='true'
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX='
\u08' # have an empty line above the prompt
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX=' \u276F ' # ❯
POWERLEVEL9K_FAIL_ICON='\u2718' # ✘
POWERLEVEL9K_VCS_CLEAN_FOREGROUND=000
POWERLEVEL9K_VCS_CLEAN_BACKGROUND=002
POWERLEVEL9K_VCS_MODIFIED_FOREGROUND=000
POWERLEVEL9K_VCS_MODIFIED_BACKGROUND=011
POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND=000
POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND=013
POWERLEVEL9K_SHORTEN_DELIMITER=$'\U2026'
POWERLEVEL9K_HOME_ICON=$'\UF015'
POWERLEVEL9K_HOME_SUB_ICON=$'\UF07C'
POWERLEVEL9K_FOLDER_ICON=$'\UF115'
# taken from powerlevel9k:
# Determine the correct sed parameter.
#
# `sed` is unfortunately not consistent across OSes when it comes to flags.
SED_EXTENDED_REGEX_PARAMETER="r"; [ $(uname) = "Darwin" ] && sed --version &>> /dev/null || SED_EXTENDED_REGEX_PARAMETER="E"
# Given a directory path, truncate it according to the settings for
# `truncate_from_right`
truncatePathFromRight() {
local delim_len=${#POWERLEVEL9K_SHORTEN_DELIMITER:-1}
echo $1 | sed -$SED_EXTENDED_REGEX_PARAMETER \
"s@(([^/]{$((POWERLEVEL9K_SHORTEN_DIR_LENGTH))})([^/]{$delim_len}))[^/]+/@\2$POWERLEVEL9K_SHORTEN_DELIMITER/@g"
}
remove_private_from_tmp_on_macos() {
local dir="$1"
if [ $(uname) = "Darwin" ] ; then
case "$dir" in
/private/tmp/*)
dir="$(echo -n "$dir" | sed -e "s#/private##g")"
esac
fi
echo -n "$dir"
}
git_toplevel_dir() {
if [[ -z "$my_git_dir_set" ]]; then
my_git_dir_set="true"
my_git_dir="$(git rev-parse --show-toplevel 2>/dev/null)"
fi
echo -n "$(remove_private_from_tmp_on_macos "$my_git_dir")"
}
prompt_dir_or_repository_toplevel_dir() {
local icon=''
if [[ $(print -P "%~") == '~' ]]; then
icon="$POWERLEVEL9K_HOME_ICON"
elif [[ $(print -P "%~") == '~'* ]]; then
icon="$POWERLEVEL9K_HOME_SUB_ICON"
else
icon="$POWERLEVEL9K_FOLDER_ICON"
fi
local base_dir=$(git_toplevel_dir)
if [[ -n "$base_dir" ]]; then
echo -n "$icon $(truncatePathFromRight "$(echo -n "$base_dir" | sed -e "s,^$HOME,~,")" )"
else
echo -n "$icon $(truncatePathFromRight "$($(remove_private_from_tmp_on_macos pwd) | sed -e "s,^$HOME,~,")" )"
fi
}
prompt_repository_cwd() {
local base_dir=$(git_toplevel_dir)
if [ -n "$base_dir" ]; then
local project_pwd=$(echo "$(remove_private_from_tmp_on_macos "$(pwd)")" | sed -e "s*$base_dir**g" -e 's*^/**')
echo -n "$project_pwd"
fi
}
POWERLEVEL9K_CUSTOM_DIR_OR_REPOSITORY_TOPLEVEL_DIR="prompt_dir_or_repository_toplevel_dir"
POWERLEVEL9K_CUSTOM_DIR_OR_REPOSITORY_TOPLEVEL_DIR_BACKGROUND=012
POWERLEVEL9K_CUSTOM_DIR_OR_REPOSITORY_TOPLEVEL_DIR_FOREGROUND=000
POWERLEVEL9K_CUSTOM_REPOSITORY_CWD="prompt_repository_cwd"
POWERLEVEL9K_CUSTOM_REPOSITORY_CWD_BACKGROUND=000
POWERLEVEL9K_CUSTOM_REPOSITORY_CWD_FOREGROUND=007
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status command_execution_time root_indicator context custom_dir_or_repository_toplevel_dir vcs custom_repository_cwd)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(battery time)
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_package_name"
POWERLEVEL9K_SHORTEN_DIR_LENGTH=4
POWERLEVEL9K_TIME_FORMAT="\uf073 %D{%d.%m.%y} \uf017 %D{%H:%M}"
POWERLEVEL9K_TIME_ICON=""
POWERLEVEL9K_TIME_FOREGROUND=000
POWERLEVEL9K_TIME_BACKGROUND=007
POWERLEVEL9K_STATUS_VERBOSE=false
POWERLEVEL9K_COMMAND_EXECUTION_TIME_STRING='\uF2D8'
POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND=010
POWERLEVEL9K_COMMAND_EXECUTION_TIME_BACKGROUND=0
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=10
POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment