Conditional alias not working
Describe the bug
❯ alias test = if (sys).host.name == "Windows" { bash 'C:\Program Files\nodejs\npm' } else { ^npm }
~
❯ test -v
Error: nu::parser::parse_mismatch (link)
× Parse mismatch during operation.
╭─[entry #31:1:1]
1 │ test -v
· ─┬
· ╰── expected operator
╰────
How to reproduce
See above
Expected behavior
I would expect that the alias would seemlessly operate as either of the conditional branches
Screenshots
No response
Configuration
| key | value |
|---|---|
| version | 0.63.0 |
| branch | |
| commit_hash | 06cf3fa5ad8c8b1d1351c81ccea59a1f8d588dc9 |
| build_os | windows-x86_64 |
| build_target | x86_64-pc-windows-msvc |
| rust_version | rustc 1.61.0 (fe5b13d68 2022-05-18) |
| rust_channel | stable-x86_64-pc-windows-msvc |
| cargo_version | cargo 1.61.0 (a028ae42f 2022-04-29) |
| pkg_version | 0.63.0 |
| build_time | 2022-05-25 01:15:47 +00:00 |
| build_rust_channel | release |
| features | database, dataframe, default, trash, which, zip |
| installed_plugins |
Additional context
No response
I'm not sure it makes a difference unless there's a problem with sys but you could try $nu.os-info.name to check the os. It should be many times faster. It's also a little weird to me that you're calling bash on windows if it's windows. Another solution is just to put the nodejs folder in your PATH on windows, then you should just be able to npm.
The reason for this workaround is because npm.cmd gives problems on my system, while the bash script works fine. But it is beside the point of this issue, which is about nu giving a parse error on an alias, which is something I do not understand.
what happens if you put the part on the right side of the = in parentheses?
@fdncred The same behavior.
I got a little closer with this alias test = (if $nu.os-info.name == windows { bash '/mnt/c/Program Files/nodejs/npm' } else { ^npm }) but the syntax highlighter is still seeing -v as valid when i do test -v.
Hey it seems I've run into a problem that could be related.
~
❯ alias doom = if (sys).host.hostname == bloodsong {
::: ^/home/antoni/.emacs.d/bin/doom
::: } else {
::: ^/home/antoni/doomemacs/bin/doom
::: }
~
❯ doom help
Error: nu::parser::extra_positional (link)
× Extra positional argument.
╭─[entry #8:1:1]
1 │ doom help
· ──┬─
· ╰── extra positional argument
╰────
help: Usage: if <cond> <then_block> (else <else_expression>)
I think this comes from aliases not being evaluated when they are aliased. Don't know if this is intended behaviour.