From 0aaf99985754cc0759ca3b7e94bdee111d5a94f8 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Nov 2015 21:04:58 +0100 Subject: [PATCH 1/7] For ZSH 5.0.8 `whence -v` tells also the path to the command. In that case we can use that information to get a proper path to the utility functions. --- powerlevel9k.zsh-theme | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 002267f4..727461d1 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -19,9 +19,15 @@ # Check if the theme was called as a function. if [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then - # Script is a function! We assume this to happen only in - # prezto, as they use the zstyle-builtin to set the theme. - 0="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" + autoload -U is-at-least + if is-at-least 5.0.8; then + # Try to find the correct path of the script. + 0=$(whence -v $0 | sed "s/$0 is a shell function from //") + else + # Script is a function! We assume this to happen only in + # prezto, as they use the zstyle-builtin to set the theme. + 0="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" + fi fi # Check if filename is a symlink. From a0323b7e8075a8b59d671a48484117e5152bebf9 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Nov 2015 21:26:50 +0100 Subject: [PATCH 2/7] The installation path of powerlevel9k is now configurable by setting the variable POWERLEVEL9K_INSTALLATION_PATH. The value must be set to the exact location of the powerlevel9k.zsh-theme file (including the file name). This has only effect if you load your theme as a function and your ZSH version is below 5.0.8. --- powerlevel9k.zsh-theme | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 727461d1..29f9804c 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -26,7 +26,9 @@ if [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then else # Script is a function! We assume this to happen only in # prezto, as they use the zstyle-builtin to set the theme. - 0="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" + [[ -z "$POWERLEVEL9K_INSTALLATION_PATH" ]] && POWERLEVEL9K_INSTALLATION_PATH="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" + + 0=$POWERLEVEL9K_INSTALLATION_PATH fi fi From 727b3e501b9f534871ed3ec0d5d6dbca1344a5c5 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Nov 2015 21:29:20 +0100 Subject: [PATCH 3/7] Now the script just returns instead of exiting with an errorcode. The reason for this is that users can't log in anymore if the specified a wrong path in POWERLEVEL9K_INSTALLATION_PATH and the script `exit`s. With `return` not the whole shell is terminated, so users get an ugly prompt, but are still able to modify .zshrc. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 29f9804c..f0cbd9f2 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -41,7 +41,7 @@ elif [[ -f $0 ]]; then filename="$0" else print -P "%F{red}Script location could not be found!%f" - exit 1 + return 1 fi script_location="$(dirname $filename)" From 972e24ad4132694d3c366678eb942799d1cd09a1 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 01:26:24 +0100 Subject: [PATCH 4/7] Added more checks to find the installation dir. Now we try to find prezto automatically and print a nice warning as a fallback. --- powerlevel9k.zsh-theme | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f0cbd9f2..dfada2e1 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -23,10 +23,16 @@ if [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then if is-at-least 5.0.8; then # Try to find the correct path of the script. 0=$(whence -v $0 | sed "s/$0 is a shell function from //") + elif [[ -f "${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/init.zsh" ]]; then + # If there is an prezto installation, we assume that powerlevel9k is linked there. + 0="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" else - # Script is a function! We assume this to happen only in - # prezto, as they use the zstyle-builtin to set the theme. - [[ -z "$POWERLEVEL9K_INSTALLATION_PATH" ]] && POWERLEVEL9K_INSTALLATION_PATH="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" + # Fallback: specify an installation path! + if [[ -z "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then + 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 + fi 0=$POWERLEVEL9K_INSTALLATION_PATH fi From 46575182c78d441eacf928fd368a4c20b1aaa0b5 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 01:33:33 +0100 Subject: [PATCH 5/7] Fallback mechanism is now more robust. If does not matter if the user specified a file or a directory in `POWERLEVEL9K_INSTALLATION_PATH`. --- powerlevel9k.zsh-theme | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index dfada2e1..610b2cbe 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -32,6 +32,10 @@ if [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then 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 + elif [[ -f "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then + 0="$POWERLEVEL9K_INSTALLATION_PATH" + elif [[ -d "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then + 0="${POWERLEVEL9K_INSTALLATION_PATH}/powerlevel9k.zsh-theme" fi 0=$POWERLEVEL9K_INSTALLATION_PATH From b01588e2f96fdc0da8df8cef14895b1e22384da7 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 01:56:26 +0100 Subject: [PATCH 6/7] File might be a symlink. --- powerlevel9k.zsh-theme | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 610b2cbe..624f7a57 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -32,9 +32,14 @@ if [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then 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 + elif [[ -L "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then + # Symlink + 0="$POWERLEVEL9K_INSTALLATION_PATH" elif [[ -f "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then + # File 0="$POWERLEVEL9K_INSTALLATION_PATH" elif [[ -d "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then + # Directory 0="${POWERLEVEL9K_INSTALLATION_PATH}/powerlevel9k.zsh-theme" fi From 8c71a28a77a3e2edebaaddd6245534f9f4514aaa Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Nov 2015 19:45:49 +0100 Subject: [PATCH 7/7] The script location should only be set once! --- powerlevel9k.zsh-theme | 2 -- 1 file changed, 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 624f7a57..bcdacd0e 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -42,8 +42,6 @@ if [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then # Directory 0="${POWERLEVEL9K_INSTALLATION_PATH}/powerlevel9k.zsh-theme" fi - - 0=$POWERLEVEL9K_INSTALLATION_PATH fi fi