diff options
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-x | powerlevel9k.zsh-theme | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 25e43074..8a4d5cb6 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -748,6 +748,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 @@ -814,23 +839,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) @@ -1119,11 +1131,10 @@ prompt_vpn_ip() { ################################################################ # Segment to display laravel version prompt_laravel_version() { - local laravel_version="$(php artisan --version 2>/dev/null)" - if [[ -n "${laravel_version}" ]]; then - # Remove unrelevant infos - laravel_version="${laravel_version//Laravel Framework version /}" - + local laravel_version="$(php artisan --version 2> /dev/null)" + if [[ -n "${laravel_version}" && "${laravel_version}" =~ "Laravel Framework" ]]; then + # Strip out everything but the version + laravel_version="${laravel_version//Laravel Framework /}" "$1_prompt_segment" "$0" "$2" "maroon" "white" "${laravel_version}" 'LARAVEL_ICON' fi } @@ -1638,7 +1649,11 @@ prompt_pyenv() { "$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="$(pyenv version-file-read $(pyenv root)/version)" + 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 |