mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-12-12 19:18:28 +02:00
Cleaned up installation directory detection
- Used ZSH built-in magic to get the installation directory. - Works with symlinks. - No longer calls out to external program 'dirname'. - Fixed issue with spaces in the path. - No longer leak the variables 'filename' and 'script_location'.
This commit is contained in:
parent
3c3a86a42f
commit
3bf0f18e26
@ -17,74 +17,57 @@
|
|||||||
################################################################
|
################################################################
|
||||||
|
|
||||||
## Turn on for Debugging
|
## Turn on for Debugging
|
||||||
|
#PS4='%s%f%b%k%F{blue}%{λ%}%L %F{240}%N:%i%(?.. %F{red}%?) %1(_.%F{yellow}%-1_ .)%s%f%b%k '
|
||||||
#zstyle ':vcs_info:*+*:*' debug true
|
#zstyle ':vcs_info:*+*:*' debug true
|
||||||
#set -o xtrace
|
#set -o xtrace
|
||||||
|
|
||||||
# Try to set the installation path
|
# Try to set the installation path
|
||||||
if [[ -n "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then
|
if [[ -n "$POWERLEVEL9K_INSTALLATION_DIR" ]]; then
|
||||||
# If an installation path was set manually,
|
p9k_directory=${POWERLEVEL9K_INSTALLATION_DIR:A}
|
||||||
# it should trump any other location found.
|
else
|
||||||
# Do nothing. This is all right, as we use the
|
if [[ "${(%):-%N}" == '(eval)' ]]; then
|
||||||
# POWERLEVEL9K_INSTALLATION_PATH for further processing.
|
if [[ "$0" == '-antigen-load' ]] && [[ -r "${PWD}/powerlevel9k.zsh-theme" ]]; then
|
||||||
elif [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then
|
# Antigen uses eval to load things so it can change the plugin (!!)
|
||||||
# Check if the theme was called as a function (e.g., from prezto)
|
# https://github.com/zsh-users/antigen/issues/581
|
||||||
autoload -U is-at-least
|
p9k_directory=$PWD
|
||||||
if is-at-least 5.0.8; then
|
else
|
||||||
# Try to find the correct path of the script.
|
print -P "%F{red}You must set POWERLEVEL9K_INSTALLATION_DIR work from within an (eval).%f"
|
||||||
POWERLEVEL9K_INSTALLATION_PATH=$(whence -v $0 | sed "s/$0 is a shell function from //")
|
return 1
|
||||||
elif [[ -f "${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/init.zsh" ]]; then
|
fi
|
||||||
# If there is an prezto installation, we assume that powerlevel9k is linked there.
|
else
|
||||||
POWERLEVEL9K_INSTALLATION_PATH="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup"
|
# Get the path to file this code is executing in; then
|
||||||
|
# get the absolute path and strip the filename.
|
||||||
|
# See https://stackoverflow.com/a/28336473/108857
|
||||||
|
p9k_directory=${${(%):-%x}:A:h}
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
# Last resort: Set installation path is script path
|
|
||||||
POWERLEVEL9K_INSTALLATION_PATH="$0"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Resolve the installation path
|
|
||||||
if [[ -L "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then
|
|
||||||
# If this theme is sourced as a symlink, we need to locate the real URL
|
|
||||||
filename="${POWERLEVEL9K_INSTALLATION_PATH:A}"
|
|
||||||
elif [[ -d "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then
|
|
||||||
# Directory
|
|
||||||
filename="${POWERLEVEL9K_INSTALLATION_PATH}/powerlevel9k.zsh-theme"
|
|
||||||
elif [[ -f "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then
|
|
||||||
# Script is a file
|
|
||||||
filename="$POWERLEVEL9K_INSTALLATION_PATH"
|
|
||||||
elif [[ -z "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then
|
|
||||||
# Fallback: specify an installation path!
|
|
||||||
print -P "%F{red}We could not locate the installation path of powerlevel9k.%f"
|
|
||||||
print -P "Please specify by setting %F{blue}POWERLEVEL9K_INSTALLATION_PATH%f (full path incl. file name) at the very beginning of your ~/.zshrc"
|
|
||||||
return 1
|
|
||||||
else
|
|
||||||
print -P "%F{red}Script location could not be found! Maybe your %F{blue}POWERLEVEL9K_INSTALLATION_PATH%F{red} is not correct?%f"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
script_location="$(dirname $filename)"
|
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
# Source icon functions
|
# Source icon functions
|
||||||
################################################################
|
################################################################
|
||||||
|
|
||||||
source $script_location/functions/icons.zsh
|
source "${p9k_directory}/functions/icons.zsh"
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
# Source utility functions
|
# Source utility functions
|
||||||
################################################################
|
################################################################
|
||||||
|
|
||||||
source $script_location/functions/utilities.zsh
|
source "${p9k_directory}/functions/utilities.zsh"
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
# Source color functions
|
# Source color functions
|
||||||
################################################################
|
################################################################
|
||||||
|
|
||||||
source $script_location/functions/colors.zsh
|
source "${p9k_directory}/functions/colors.zsh"
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
# Source VCS_INFO hooks / helper functions
|
# Source VCS_INFO hooks / helper functions
|
||||||
################################################################
|
################################################################
|
||||||
|
|
||||||
source $script_location/functions/vcs.zsh
|
source "${p9k_directory}/functions/vcs.zsh"
|
||||||
|
|
||||||
|
# cleanup temporary variables.
|
||||||
|
unset p9k_directory
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
# Color Scheme
|
# Color Scheme
|
||||||
|
Loading…
Reference in New Issue
Block a user