summaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
authorBen Hilburn <ben.hilburn@ettus.com>2015-08-28 17:08:13 +0300
committerBen Hilburn <ben.hilburn@ettus.com>2015-08-28 17:08:13 +0300
commitbf9ef6acf179015e422cc29a1d85799e48e1c93d (patch)
tree2b84cf9ef22111e7812dcf03ba6904b225ffe135 /powerlevel9k.zsh-theme
parentfbac091e27f3ad69e022cf24932b9219674b030f (diff)
parent7535f62746c9d172d14adfe437a8573e682a12da (diff)
Merge 'dritter/improve_shorten_dir_length' into next
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rw-r--r--powerlevel9k.zsh-theme89
1 files changed, 68 insertions, 21 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index c0ea83aa..56ecb611 100644
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -45,6 +45,21 @@
#set -o xtrace
################################################################
+# Utility functions
+################################################################
+
+function print_icon() {
+ local icon_name=$1
+ local ICON_USER_VARIABLE=POWERLEVEL9K_${icon_name}
+ local USER_ICON=${(P)ICON_USER_VARIABLE}
+ if [[ -n "$USER_ICON" ]]; then
+ echo -n $USER_ICON
+ else
+ echo -n ${icons[$icon_name]}
+ fi
+}
+
+################################################################
# Icons
################################################################
@@ -75,6 +90,7 @@ case $POWERLEVEL9K_MODE in
FREEBSD_ICON $'\U1F608 ' # 😈
LINUX_ICON $'\U1F427 ' # 🐧
SUNOS_ICON $'\U1F31E ' # 🌞
+ HOME_ICON $'\UE12C' # 
VCS_UNTRACKED_ICON "\UE16C" # 
VCS_UNSTAGED_ICON "\UE17C" # 
VCS_STAGED_ICON "\UE168" # 
@@ -115,6 +131,7 @@ case $POWERLEVEL9K_MODE in
FREEBSD_ICON 'BSD'
LINUX_ICON 'Lx'
SUNOS_ICON 'Sun'
+ HOME_ICON ''
VCS_UNTRACKED_ICON '?'
VCS_UNSTAGED_ICON "\u25CF" # ●
VCS_STAGED_ICON "\u271A" # ✚
@@ -149,28 +166,47 @@ if [[ "$POWERLEVEL9K_HIDE_BRANCH_ICON" == true ]]; then
icons[VCS_BRANCH_ICON]=''
fi
-function print_icon() {
- local icon_name=$1
- local ICON_USER_VARIABLE=POWERLEVEL9K_${icon_name}
- local USER_ICON=${(P)ICON_USER_VARIABLE}
- if [[ -n "$USER_ICON" ]]; then
- echo -n $USER_ICON
- else
- echo -n ${icons[$icon_name]}
- fi
-}
-
# OS detection for the `os_icon` segment
case $(uname) in
- "Darwin") OS_ICON=$(print_icon 'APPLE_ICON') ;;
- "FreeBSD") OS_ICON=$(print_icon 'FREEBSD_ICON') ;;
- "OpenBSD") OS_ICON=$(print_icon 'FREEBSD_ICON') ;;
- "DragonFly") OS_ICON=$(print_icon 'FREEBSD_ICON') ;;
- "Linux") OS_ICON=$(print_icon 'LINUX_ICON') ;;
- "SunOS") OS_ICON=$(print_icon 'SUNOS_ICON') ;;
- *) OS_ICON='' ;;
+ Darwin)
+ OS='OSX'
+ OS_ICON=$(print_icon 'APPLE_ICON')
+ ;;
+ FreeBSD)
+ OS='BSD'
+ OS_ICON=$(print_icon 'FREEBSD_ICON')
+ ;;
+ OpenBSD)
+ OS='BSD'
+ OS_ICON=$(print_icon 'FREEBSD_ICON')
+ ;;
+ DragonFly)
+ OS='BSD'
+ OS_ICON=$(print_icon 'FREEBSD_ICON')
+ ;;
+ Linux)
+ OS='Linux'
+ OS_ICON=$(print_icon 'LINUX_ICON')
+ ;;
+ SunOS)
+ OS='Solaris'
+ OS_ICON=$(print_icon 'SUNOS_ICON')
+ ;;
+ *)
+ OS=''
+ OS_ICON=''
+ ;;
esac
+# Determine the correct sed parameter.
+SED_EXTENDED_REGEX_PARAMETER="-r"
+if [[ "$OS" == 'OSX' ]]; then
+ local IS_BSD_SED=$(sed --version &>> /dev/null || echo "BSD sed")
+ if [[ -n "$IS_BSD_SED" ]]; then
+ SED_EXTENDED_REGEX_PARAMETER="-E"
+ fi
+fi
+
################################################################
# color scheme
################################################################
@@ -457,11 +493,22 @@ prompt_context() {
prompt_dir() {
local current_path='%~'
if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" ]]; then
- # shorten path to $POWERLEVEL9K_SHORTEN_DIR_LENGTH
- current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:.../:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c"
+
+ case "$POWERLEVEL9K_SHORTEN_STRATEGY" in
+ truncate_middle)
+ current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1\.\.\2\//g")
+ ;;
+ truncate_from_right)
+ current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1..\//g")
+ ;;
+ *)
+ current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:.../:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c"
+ ;;
+ esac
+
fi
- $1_prompt_segment "$0" "blue" "$DEFAULT_COLOR" "$current_path"
+ $1_prompt_segment "$0" "blue" "$DEFAULT_COLOR" "$(print_icon 'HOME_ICON') $current_path"
}
# Command number (in local history)