summaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-xpowerlevel9k.zsh-theme77
1 files changed, 49 insertions, 28 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 8af3cb61..0b2287ef 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -745,6 +745,31 @@ prompt_command_execution_time() {
}
################################################################
+# Determine the unique path - this is needed for the
+# truncate_to_unique strategy.
+#
+function getUniqueFolder() {
+ local trunc_path directory test_dir test_dir_length
+ local -a matching
+ local -a paths
+ local cur_path='/'
+ paths=(${(s:/:)1})
+ for directory in ${paths[@]}; do
+ test_dir=''
+ for (( i=0; i < ${#directory}; i++ )); do
+ test_dir+="${directory:$i:1}"
+ matching=("$cur_path"/"$test_dir"*/)
+ if [[ ${#matching[@]} -eq 1 ]]; then
+ break
+ fi
+ done
+ trunc_path+="$test_dir/"
+ cur_path+="$directory/"
+ done
+ echo "${trunc_path: : -1}"
+}
+
+################################################################
# Dir: current working directory
# Parameters:
# * $1 Alignment: string - left|right
@@ -811,23 +836,10 @@ prompt_dir() {
# for each parent path component find the shortest unique beginning
# characters sequence. Source: https://stackoverflow.com/a/45336078
if (( ${#current_path} > 1 )); then # root and home are exceptions and won't have paths
- local matching
- local cur_path='/'
- [[ $current_path != "~"* ]] && trunc_path='/' || trunc_path=''
- for directory in ${paths[@]}; do
- test_dir=''
- for (( i=0; i<${#directory}; i++ )); do
- test_dir+="${directory:$i:1}"
- matching=("$cur_path"/"$test_dir"*/)
- if [[ ${#matching[@]} -eq 1 ]]; then
- break
- fi
- done
- trunc_path+="$test_dir/"
- cur_path+="$directory/"
- done
- [[ $current_path == "~"* ]] && trunc_path="~/$trunc_path"
- current_path="${trunc_path: : -1}"
+ # cheating here to retain ~ as home folder
+ local home_path="$(getUniqueFolder $HOME)"
+ trunc_path="$(getUniqueFolder $PWD)"
+ [[ $current_path == "~"* ]] && current_path="~${trunc_path//${home_path}/}" || current_path="/${trunc_path}"
fi
;;
truncate_with_folder_marker)
@@ -1259,21 +1271,19 @@ prompt_ram() {
"$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$(printSizeHumanReadable "$ramfree" $base)" 'RAM_ICON'
}
-
+################################################################
+# Segment to display rbenv information
+# https://github.com/rbenv/rbenv#choosing-the-ruby-version
set_default POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW false
-# rbenv information
prompt_rbenv() {
- if command which rbenv 2>/dev/null >&2; then
+ if [[ -n "$RBENV_VERSION" ]]; then
+ "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "$RBENV_VERSION" 'RUBY_ICON'
+ elif [ $commands[rbenv] ]; then
local rbenv_version_name="$(rbenv version-name)"
local rbenv_global="$(rbenv global)"
-
- # Don't show anything if the current Ruby is the same as the global Ruby
- # unless `POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW` is set.
- if [[ $rbenv_version_name == $rbenv_global && "$POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW" = false ]]; then
- return
+ if [[ "${rbenv_version_name}" != "${rbenv_global}" || "${POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW}" == "true" ]]; then
+ "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "$rbenv_version_name" 'RUBY_ICON'
fi
-
- "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "$rbenv_version_name" 'RUBY_ICON'
fi
}
@@ -1627,11 +1637,22 @@ prompt_virtualenv() {
}
################################################################
-# pyenv: current active python version (with restrictions)
+# Segment to display pyenv information
# https://github.com/pyenv/pyenv#choosing-the-python-version
+set_default POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW false
prompt_pyenv() {
if [[ -n "$PYENV_VERSION" ]]; then
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$PYENV_VERSION" 'PYTHON_ICON'
+ elif [ $commands[pyenv] ]; then
+ local pyenv_version_name="$(pyenv version-name)"
+ local pyenv_global="system"
+ local pyenv_root="$(pyenv root)"
+ if [[ -f "${pyenv_root}/version" ]]; then
+ pyenv_global="$(pyenv version-file-read ${pyenv_root}/version)"
+ fi
+ if [[ "${pyenv_version_name}" != "${pyenv_global}" || "${POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW}" == "true" ]]; then
+ "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$pyenv_version_name" 'PYTHON_ICON'
+ fi
fi
}