Closed meramsey closed 2 years ago
What is xonsh
? Is it POSIX-compliant? That (and zsh) is all that nvm supports.
(also, nvm very much does NOT work for fish, since fish is not posix-compliant)
More about Xonsh https://xon.sh/ https://github.com/xonsh/xonsh https://xon.sh/contents.html#comparison
Not sure if its considered POSIX-compliant but asking to find out.
It very much doesn't look it - and the syntax error in your OP means it doesn't support normal POSIX functions.
Put another way, if it were POSIX-compliant, it would already work - if it doesn't, it's a bug (or a flaw) in that shell, and there's unlikely to be anything nvm can do to handle it.
Makes sense. Figured I'd ask cause not seen any of the other stuff have this issue but I totally get it from your point of view.
It looks like i can get it to work with the other bash compatible thing I use in xonsh which is one way to achieve my needs
I just can't yet bookmark the whole monster command alias where it works with just the nvm like in other shells, but that is something I can figure out or ask for help elsewhere with. Thanks for the super fast response and taking the time to look.
Have a wonderful day and keep up the amazing work your doing!
Glad you got it to work!
If it does turn out that there's something small I can do to improve compatibility with xonsh, I'm happy to do it, but "rewriting every funciton" isn't viable :-)
Thanks. I totally understand and would not want you to go through rewriting all those functions. Which is why when I saw that many I was like yeah that's out of my league lol.
If you can put in the README.md something about how to use in xonsh shell that would be swell. Thanks to the genius @anki-code https://github.com/anki-code/xontrib-sh/issues/6
Simply adding this one line of code to a user's ~/.xonshrc file
aliases['nvm'] = """bash -c @(f'[ -s "{$HOME}/.nvm/nvm.sh" ] && . "{$HOME}/.nvm/nvm.sh" && nvm {" ".join($args)}')"""
Works perfectly like it does in every other shell now so I don't have to switch to zsh or bash anymore for nvm related things.
Is equivalent to doing this in your bashc
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Not super important but would be nice. Potentially you could auto add or suggest it to users to add if you detect there is an ~/.xonshrc
Looks like detection is here? https://github.com/nvm-sh/nvm/blob/master/install.sh#L256-L300
Suggestion output is here? https://github.com/nvm-sh/nvm/blob/master/install.sh#L411-L460
Also I see that you have scripts for auto activating nvm use I'm going to try to see if I can make something like that for xonsh and if I get it working will probably submit a PR.
Once again thanks for being so awesome and friendly.
Alternatively you can use rtx to manage your versions. It supports reading .nvmrc
, .node-version
and files specific to other languages/tools it supports.
Operating system and version:
NAME="Pop!_OS" VERSION="21.10" ID=pop ID_LIKE="ubuntu debian" PRETTY_NAME="Pop!_OS 21.10" VERSION_ID="21.10" HOME_URL="https://pop.system76.com" SUPPORT_URL="https://support.system76.com" BUG_REPORT_URL="https://github.com/pop-os/pop/issues" PRIVACY_POLICY_URL="https://system76.com/privacy" VERSION_CODENAME=impish UBUNTU_CODENAME=impish LOGO=distributor-logo-pop-os
nvm debug
output:nvm ls
output:How did you install
nvm
?install script in readme
What steps did you perform?
tried to execute script in xonsh shell
What happened?
@ nvm debug Traceback (most recent call last): File "/home/mike/.pyenv/versions/3.9.6/bin/xonsh", line 8, in
sys.exit(main())
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/amalgam.py", line 21799, in main
_failback_to_other_shells(args, err)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/amalgam.py", line 21746, in _failback_to_other_shells
raise err
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/amalgam.py", line 21797, in main
sys.exit(main_xonsh(args))
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/amalgam.py", line 21853, in main_xonsh
run_script_with_cache(
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/amalgam.py", line 3660, in run_script_with_cache
ccode = compile_code(filename, code, execer, glb, loc, mode)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/amalgam.py", line 3619, in compile_code
ccode = execer.compile(code, glbs=glb, locs=loc, mode=mode, filename=filename)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/amalgam.py", line 14382, in compile
tree = self.parse(input, ctx, mode=mode, filename=filename, transform=transform)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/amalgam.py", line 14340, in parse
tree, input = self._parse_ctx_free(input, mode=mode, filename=filename)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/amalgam.py", line 14489, in _parse_ctx_free
raise original_error from None
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/amalgam.py", line 14470, in _parse_ctx_free
tree = self.parser.parse(
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/parsers/base.py", line 523, in parse
tree = self.parser.parse(input=s, lexer=self.lexer, debug=debug_level)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/ply/ply/yacc.py", line 335, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/ply/ply/yacc.py", line 1203, in parseopt_notrack
tok = call_errorfunc(self.errorfunc, errtoken, self)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/ply/ply/yacc.py", line 194, in call_errorfunc
r = errorfunc(token)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/parsers/base.py", line 3459, in p_error
self._parse_error(msg, self.currloc(lineno=p.lineno, column=p.lexpos))
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/parsers/base.py", line 650, in _parse_error
raise_parse_error(msg, loc, self.xonsh_code, self.lines)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/parsers/base.py", line 238, in raise_parse_error
raise err
SyntaxError: /home/mike/.nvm/nvm.sh:16:0: ('code: nvm_is_zsh',)
nvm_is_zsh() {
^
~ [✖ ERROR] at 16:43:04
@
What did you expect to happen?
expected it to be callable from xonsh shell like it would be for zsh fish bash etc.
Is there anything in any of your profile files that modifies the
PATH
?Yes but its there so xonsh know where it is. lines to add it to my .xonshrc
tried also sourcing it with zsh/bash thing xonsh offers but it fails that too :(
More about xonsh https://xon.sh/
Seems to be that it requires zsh and even if sourced from another shell it doesn't seem to like that check https://github.com/nvm-sh/nvm/blob/master/nvm.sh#L16-L18
On zsh get a value
In bash no value
It looks like the reason for this may be due to using getting that version from the variable
${ZSH_VERSION-}
which has {} and the -https://xon.sh/bash_to_xsh.html
What i don't know is why that is even needed though cause echoing out both ${ZSH_VERSION-} and ${ZSH_VERSION} in zsh gets you the same value. So it seems weird that not having that value would break things.
I could be missing something but maybe an exclusion could be based so having that fail isn't instant failure for what should otherwise work.
It looks like other projects ive seen do redundant checks vs just for zsh sdkman
Some other references https://www.av8n.com/computer/shell-dialect-detect
My xonsh env in case that's helpful: