From 9aeff8d43bd8ad95d913b21e68a5aa64036eda45 Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Thu, 14 Jan 2016 11:05:26 -0700 Subject: [PATCH 1/5] added check for nvm command before running --- powerlevel9k.zsh-theme | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c01c9a9d..ab942d5b 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -531,10 +531,12 @@ prompt_node_version() { # Node version from NVM # Only prints the segment if different than the default value prompt_nvm() { - local node_version=$(nvm current) - local nvm_default=$(cat $NVM_DIR/alias/default) - [[ -z "${node_version}" ]] && return - [[ "$node_version" =~ "$nvm_default" ]] && return + if [[ $(type nvm) =~ 'nvm is a shell function'* ]]; then + local node_version=$(nvm current) + local nvm_default=$(cat $NVM_DIR/alias/default) + [[ -z "${node_version}" ]] && return + [[ "$node_version" =~ "$nvm_default" ]] && return + fi $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1}" 'NODE_ICON' } From e29b3545bd4dc22f874347df9eb296e62105b94e Mon Sep 17 00:00:00 2001 From: rjorgenson Date: Thu, 14 Jan 2016 11:07:11 -0700 Subject: [PATCH 2/5] fixed called to ioreg on OS X machines --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index ab942d5b..451d1b6f 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -312,7 +312,7 @@ prompt_battery() { if [[ $OS =~ OSX && -f /usr/sbin/ioreg && -x /usr/sbin/ioreg ]]; then # Pre-Grep as much information as possible to save some memory and # avoid pollution of the xtrace output. - local raw_data=$(ioreg -n AppleSmartBattery | grep -E "MaxCapacity|TimeRemaining|CurrentCapacity|ExternalConnected|IsCharging") + local raw_data="$(ioreg -n AppleSmartBattery | grep -E "MaxCapacity|TimeRemaining|CurrentCapacity|ExternalConnected|IsCharging")" # return if there is no battery on system [[ -z $(echo $raw_data | grep MaxCapacity) ]] && return From 2fa7b1d08f55e71397f13f4e943491426b0e98c0 Mon Sep 17 00:00:00 2001 From: Robert Jorgenson Date: Thu, 14 Jan 2016 14:09:39 -0700 Subject: [PATCH 3/5] don't output segment if node_version was not populated --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 451d1b6f..23e53221 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -538,7 +538,7 @@ prompt_nvm() { [[ "$node_version" =~ "$nvm_default" ]] && return fi - $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1}" 'NODE_ICON' + [[ -n "${node_version}" ]] && $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1}" 'NODE_ICON' } # print a little OS icon From 446f46473b2620bbe416488b68dd099be27f695a Mon Sep 17 00:00:00 2001 From: Robert Jorgenson Date: Thu, 14 Jan 2016 16:16:27 -0700 Subject: [PATCH 4/5] reworked nvm check Now the prompt segment just returns without doing anything if nvm is not present. --- powerlevel9k.zsh-theme | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 23e53221..95849e99 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -531,14 +531,13 @@ prompt_node_version() { # Node version from NVM # Only prints the segment if different than the default value prompt_nvm() { - if [[ $(type nvm) =~ 'nvm is a shell function'* ]]; then - local node_version=$(nvm current) - local nvm_default=$(cat $NVM_DIR/alias/default) - [[ -z "${node_version}" ]] && return - [[ "$node_version" =~ "$nvm_default" ]] && return - fi + [[ $(type nvm) =~ 'nvm is a shell function'* ]] && return + local node_version=$(nvm current) + local nvm_default=$(cat $NVM_DIR/alias/default) + [[ -z "${node_version}" ]] && return + [[ "$node_version" =~ "$nvm_default" ]] && return - [[ -n "${node_version}" ]] && $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1}" 'NODE_ICON' + $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1}" 'NODE_ICON' } # print a little OS icon From 6f2f78b21fe597ad55e5f87360b68b4a812a7d19 Mon Sep 17 00:00:00 2001 From: Robert Jorgenson Date: Thu, 14 Jan 2016 16:19:12 -0700 Subject: [PATCH 5/5] fixed conditional statement --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 95849e99..3e2beff0 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -531,7 +531,7 @@ prompt_node_version() { # Node version from NVM # Only prints the segment if different than the default value prompt_nvm() { - [[ $(type nvm) =~ 'nvm is a shell function'* ]] && return + [[ ! $(type nvm) =~ 'nvm is a shell function'* ]] && return local node_version=$(nvm current) local nvm_default=$(cat $NVM_DIR/alias/default) [[ -z "${node_version}" ]] && return