Nushell support#6873
Conversation
Auto-reloading is not yet implemented
| let config_home = | ||
| try Env.get "XDG_CONFIG_HOME" | ||
| with Not_found -> home ".config" | ||
| in | ||
| Some (List.fold_left Filename.concat config_home ["nushell"; "autoload"; "opam.nu"]) |
There was a problem hiding this comment.
the default config location seems to be a bit more complicated than that. In particular, the default $HOME/.config/... is only true on Linux, not macOS or Windows (see https://www.nushell.sh/book/configuration.html#configuration-overview)
There was a problem hiding this comment.
I took a stab at improving it, but it's untested on macOS and Windows. For background, nushell uses the dirs crate as a fallback if XDG_CONFIG_HOME is unset. It's behaviour is documented here. On windows, it actually uses win32 bindings, but some random googling suggested that maybe the APPDATA env var would also work...
| | SH_csh -> Some OpamScript.env_hook_csh | ||
| | SH_fish -> Some OpamScript.env_hook_fish | ||
| | SH_pwsh _ | SH_cmd -> None | ||
| | SH_pwsh _ | SH_cmd | SH_nu -> None |
There was a problem hiding this comment.
this seems possible using https://www.nushell.sh/book/hooks.html#pre-execution-hooks
There was a problem hiding this comment.
Not yet done, and I've run out of time for today. I'll re-request a review when it's ready for another look.
| let fname = unix_transform ~using_backslashes:true () in | ||
| Printf.sprintf "test -r '%s' && source '%s' > /dev/null 2> /dev/null; or true\n" fname fname | ||
| | SH_nu -> | ||
| Printf.sprintf "const source_path = if ('%s' | path exists) { '%s' } else { null }\nsource $source_path\n" fname fname |
There was a problem hiding this comment.
it feels like it could be shorten to
| Printf.sprintf "const source_path = if ('%s' | path exists) { '%s' } else { null }\nsource $source_path\n" fname fname | |
| Printf.sprintf "if ('%s' | path exists) { source '%s' }\n" fname fname |
There was a problem hiding this comment.
It feels like it, but no... for reasons I don't really understand, the source "dep.nu" in
if ("dep.nu" | path exists) { source "dep.nu" }is evaluated unconditionally at parse time, while the "if" condition is delayed to run time. But, if you write it as
const source_path = if ("dep.nu" | path exists) { "dep.nu"}
source $source_paththen the "if" condition is promoted to parse time. It does look like I can remove the "else null" part, though.
There was a problem hiding this comment.
ah thanks, this is explained in https://www.nushell.sh/book/thinking_in_nu.html#think-of-nushell-as-a-compiled-language
|
oops i hit enter a bit too fast. Thanks a lot for your contribution, would you have some spare time to look at the issues highlighted above. I think that once they are all fixed this should probably be in a mergeable state |
|
Thanks for the fast response! I should be able to do another iteration over the weekend. |
|
Thanks for the (follow-up) PR. We discussed it in dev meeting: we need to take into account the fact that nushell is prone to change:
Otherwise, the current content is quite ok (quite bc it needs to be reviewed). |
Do you have any guidance for how to determine "most" here? Nushell maintains a packaging status table, but it isn't completely obvious to me where to draw the line. For example, I often use Debian's packaged version to determine the oldest version that's worth supporting, but apparently Debian doesn't package nushell... |
|
That's a good question, ideally from that table, i would say "replace debian by <fairly used distribution with the oldest version of nushell>", which in this case is Fedora (0.99.1). Sadly in this case, it probably complicates things a bit too much, because So if that's not possible, i'd say probably 0.104 (latest nushell version in Alpine since 3.22) is a good starting point. |
|
I spent some time trying to add a minimal version check to the autoload script, with the goal of producing an actionable error when invoked with an old if (version | get major) == 0 and (version | get minor) < 102 {
return
}
const s = if ("dep.nu" | path exists) { "dep.nu" }
source $swith nu 0.99 gives the error The version guard has no effect, because the error occurs before anything is run. I tried a few hacks to get the version guard to run at parse time, but without success (in 0.99, not even the So maybe the best course of action is to hold off on this until 0.102 is old enough that we can assume everyone uses it. In the meantime, direnv and |
|
what about simply parsing The check would be done only once at init time but i don't expect people to start downgrading their version of nushell, and if so i think they would probably expect something to break. |
This is a continuation of #6330, adding nushell support.
As in #6330, nushell support for
opam envworks via json (so the command to populate the environment isload-env (opam env | to json)).This also adds shell config support, but doesn't yet setup any hooks.