-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for nodenv #226
Open
shaun-floss
wants to merge
1
commit into
oh-my-fish:master
Choose a base branch
from
shaun-floss:add-support-for-nodenv
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ | |
# set -g theme_display_hostname ssh | ||
# set -g theme_display_sudo_user yes | ||
# set -g theme_display_vi no | ||
# set -g theme_display_nvm yes | ||
# set -g theme_display_nodejs yes | ||
# set -g theme_avoid_ambiguous_glyphs yes | ||
# set -g theme_powerline_fonts no | ||
# set -g theme_nerd_fonts yes | ||
|
@@ -850,14 +850,35 @@ function __bobthefish_prompt_desk -S -d 'Display current desk environment' | |
set_color normal | ||
end | ||
|
||
function __bobthefish_prompt_nvm -S -d 'Display current node version through NVM' | ||
[ "$theme_display_nvm" = 'yes' -a -n "$NVM_DIR" ] | ||
function __bobthefish_prompt_nodejs -S -d 'Display current Node.js version' | ||
[ "$theme_display_nodejs" = 'yes' -o "$theme_display_nvm" = 'yes' ] | ||
or return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left the existing configuration setting |
||
|
||
set -l node_version (nvm current 2> /dev/null) | ||
set -l node_version | ||
if type -q nvm | ||
[ -n "$NVM_DIR" ] | ||
or return | ||
|
||
[ -z $node_version -o "$node_version" = 'none' -o "$node_version" = 'system' ] | ||
and return | ||
set node_version (nvm current 2> /dev/null) | ||
|
||
[ -z $node_version -o "$node_version" = 'none' -o "$node_version" = 'system' ] | ||
and return | ||
else if type -fq nodenv | ||
set node_version (nodenv version-name) | ||
|
||
# Don't show global node version... | ||
set -q NODENV_ROOT | ||
or set -l NODENV_ROOT $HOME/.nodenv | ||
|
||
[ -e "$NODENV_ROOT/version" ] | ||
and read -l global_node_version < "$NODENV_ROOT/version" | ||
|
||
[ "$global_node_version" ] | ||
or set -l global_node_version system | ||
|
||
[ "$node_version" = "$global_node_version" ] | ||
and return | ||
end | ||
|
||
__bobthefish_start_segment $color_nvm | ||
echo -ns $node_glyph $node_version ' ' | ||
|
@@ -1076,7 +1097,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' | |
__bobthefish_prompt_rubies | ||
__bobthefish_prompt_virtualfish | ||
__bobthefish_prompt_virtualgo | ||
__bobthefish_prompt_nvm | ||
__bobthefish_prompt_nodejs | ||
|
||
set -l real_pwd (__bobthefish_pwd) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about
nodenv
, but runningnvm
every time we render a prompt is slow. That's why it's opt-in rather than opt-out, and that's also why we check$NVM_DIR
and bail early, rather than callingnvm current
.I'd love to support
nodenv
, but I really don't want to slow down the prompt for everyone all the time to do it :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for responding, @bobthecow! 😃
That makes sense to me. Won't the new check/guard (right below this) ensure that we fail/bail early? 🤔
Also, I can add the check for
$NVM_DIR
to theif type -fq nvm
line if that works?Let me know what you think! 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point was that expensive checks should always be opt-in, not opt-out. And I'm not sure about
nodenv
, butnvm
is definitely expensive, so it shouldn't be on by default.Yes, the check for
$NVM_DIR
should be preserved. Maybe add it to thenvm
branch, something like…There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated this to what you suggested. 😃