Powerlevel10k: node/nvm version behavior (only show when a package.json file is present and use the nvm version)

Created on 12 Dec 2019  路  3Comments  路  Source: romkatv/powerlevel10k

I'm unsure if this is possible since there are multiple node settings. I've attached a gif.

Kapture 2019-12-11 at 21 35 31

In that node-starter directory there is a package.json file and it doesn't show the node version initially which I would expect since in the config this setting is set:

typeset -g POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY=true

However, only after I use nvm use (since there is an .nvmrc) does it show the node version, and when I do annvm use defaultit goes back to not showing it again. Also if I do annvm useand then navigate out of that directory to a directory that doesn't have apackage.json` file it still shows the node version.

What behavior I would like to happen:

It always, but only, shows the node version when the directory has a package.json file. If the directory does not have a package.json file then don't show any node information.

Thanks for this awesome theme!

Most helpful comment

At the top of ~/.p10k.zsh you can find the following definition:

# The list of segments shown on the right.
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(
  ...
  nodenv          # node.js version from nodenv (https://github.com/nodenv/nodenv)
  nvm             # node.js version from nvm (https://github.com/nvm-sh/nvm)
  nodeenv         # node.js environment (https://github.com/ekalinin/nodeenv)
  # node_version  # node.js version
  ...
)

There are several prompt segments that refer to node.js version. The last segment -- node_version -- is essentially a wrapper around node --version. Note that it's commented out (disabled). The other prompt segments fetch node version from various node version managers.

Below this, there is one section for each prompt segment that defines parameters specifically for that segment. For example, here's what the config has for node_version.

####################[ node_version: node.js version ]#####################
# Show node version only when in a directory tree containing package.json.
typeset -g POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY=true
...

POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY=true works just like you would expect. However, it has no effect if node_segment isn't enabled.

What behavior I would like to happen:

It always, but only, shows the node version when the directory has a package.json file. If the directory does not have a package.json file then don't show any node information.

You can achieve the desired behavior by uncommenting node_version and commenting out the other three node segments.

Thanks for this awesome theme!

Thanks :hugs:

All 3 comments

At the top of ~/.p10k.zsh you can find the following definition:

# The list of segments shown on the right.
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(
  ...
  nodenv          # node.js version from nodenv (https://github.com/nodenv/nodenv)
  nvm             # node.js version from nvm (https://github.com/nvm-sh/nvm)
  nodeenv         # node.js environment (https://github.com/ekalinin/nodeenv)
  # node_version  # node.js version
  ...
)

There are several prompt segments that refer to node.js version. The last segment -- node_version -- is essentially a wrapper around node --version. Note that it's commented out (disabled). The other prompt segments fetch node version from various node version managers.

Below this, there is one section for each prompt segment that defines parameters specifically for that segment. For example, here's what the config has for node_version.

####################[ node_version: node.js version ]#####################
# Show node version only when in a directory tree containing package.json.
typeset -g POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY=true
...

POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY=true works just like you would expect. However, it has no effect if node_segment isn't enabled.

What behavior I would like to happen:

It always, but only, shows the node version when the directory has a package.json file. If the directory does not have a package.json file then don't show any node information.

You can achieve the desired behavior by uncommenting node_version and commenting out the other three node segments.

Thanks for this awesome theme!

Thanks :hugs:

This worked exactly like you said! Thanks 馃檹

Thanks for the confirmation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alex-popov-tech picture alex-popov-tech  路  4Comments

gibfahn picture gibfahn  路  5Comments

bwoodruff picture bwoodruff  路  6Comments

fedemengo picture fedemengo  路  7Comments

gigglearrows picture gigglearrows  路  4Comments