Adding nu version to scripts
Hello, a recent commit (446f06f) broke the ssh custom completion for nu version 0.99.1 (the one shipped by dnf and fedora). This isn't a huge issue and I just downloaded the previous version. However, it got me thinking, should the version of nu the script was developed for be commented in the script? Ideally the script should display what versions of nu it works for, but this is unfeasible, probably.
Not sure how that could happen really. Most people try to stay updated with the latest changes.
When I need my scripts to be versioned correctly (regardless of the language I'm using), I usually use the nix tool to get the right version for the programs the script uses, it's similar to python's venv, but works with most programs.
For instance, if you want to make so that your script uses a specific version of nushell when executed, you can use a nix shebang that refers to a specific commit hash of the nix package repository:
#! /usr/bin/env nix
#! nix shell github:nixos/nixpkgs/21808d22b1cda1898b71cf1a1beb524a97add2c4#nushell --command nu
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# This is the commit hash of the nix revision that has the 0.101.0 version of nushell
# you can find the hashes of other versions here:
# https://lazamar.co.uk/nix-versions/?channel=nixpkgs-unstable&package=nushell
print $"hi from (nu --version)"
Then run the script:
$ chmod +x script.nu
$ ./script.nu
hi from 0.101.0
I was just thinking that adding a # created with nu version: 0.102.0 to the top of the file. This was just an idea to make it easier to find the last functional hash for your version.
I've actually solved this issue by just using carapace instead :P
Authors are welcome to put that in the scripts they submit.
Thank you. Those SSH completion changes were made by me. I will update my scripts to have that compatibility note.
I'll also update mine and start including those in the completions I have in queue.
How useful is a "created for version x" when a distro delivers version y and Nushell has released many more versions to z?
The Nushell documentation had a reference to a very old version at some point, which I found more confusing than helpful being on a much alter version. It implied / seemed like it would be outdated documentation.
The issue will probably only be resolved through Nushell getting stable versions (> 0).
If you add version numbers to scripts, would you add information on what it was created on and confirmed working? The first working version? The last?
I see #1057 added a header # nu-version: 0.102.0 only. As if the script were only working on or intended for that version. Or only confirmed working on that version.
I guess it would allow you to go through git history of it and determine breakpoints and then you have a selection of two versions to try?
Related / Alternative #971
I see https://github.com/nushell/nu_scripts/pull/1057 added a header # nu-version: 0.102.0 only. As if the script were only working on or intended for that version. Or only confirmed working on that version.
Similar to rust-version in Cargo.toml and requires-python, it means that is the minimum version supported.
- This is the version of Nu which the script author created with, tested with and confirm to work.
- It is also tested with some later version, and confirmed to work.
- There can be a newer version of Nu which the script author has not tested with.