Last active
February 20, 2020 21:01
-
-
Save mgaebler/697349d4a015dbbe66f1556f59e2bd6f to your computer and use it in GitHub Desktop.
Fish shell function that returns the current node version if you're using nvm
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
function __use_node_version | |
# test if .nvmrc exists | |
if test -e .nvmrc | |
# test if variable exist and compare version with .nvmrc | |
if test \( -n "$NVMRC_CURRENT" \) -a \( $NVMRC_CURRENT = (cat .nvmrc) \) > /dev/null 2>&1 | |
# node version allready set | |
else | |
# create a nvm current variable | |
set -g NVMRC_CURRENT (cat .nvmrc) | |
nvm use $NVMRC_CURRENT > /dev/null | |
#echo 'set node version' | |
end | |
end | |
end | |
function __node_version | |
if type "nvm" > /dev/null 2>&1 | |
__use_node_version | |
set node_version (nvm current) | |
else | |
set node_version "system" | |
end | |
echo -n (set_color green) ⬢ ‹$node_version› (set_color normal) | |
end | |
# it can then be used in the prompt function | |
function fish_prompt | |
# ... | |
__node_version | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment