mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-12-18 05:40:07 +00:00
Merge 'dritter/improve_shorten_dir_length' into next
This commit is contained in:
commit
bf9ef6acf1
2 changed files with 80 additions and 21 deletions
12
README.md
12
README.md
|
@ -279,6 +279,18 @@ to a certain length:
|
|||
# Limit to the last two folders
|
||||
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
|
||||
|
||||
To change the way how the current working directory is truncated, just set:
|
||||
|
||||
# truncate the middle part
|
||||
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_middle"
|
||||
# truncate from right, leaving the first X characters untouched
|
||||
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right"
|
||||
# default behaviour is to truncate whole directories
|
||||
|
||||
In each case you have to specify the length you want to shorten the directory
|
||||
to. So in some cases `POWERLEVEL9K_SHORTEN_DIR_LENGTH` means characters, in
|
||||
others whole directories.
|
||||
|
||||
#### The 'time' segment
|
||||
|
||||
By default the time is show in 'H:M:S' format. If you want to change it,
|
||||
|
|
|
@ -44,6 +44,21 @@
|
|||
#zstyle ':vcs_info:*+*:*' debug true
|
||||
#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)
|
||||
|
|
Loading…
Reference in a new issue