fish-shell / fish-shell/fish-shell
Support robust method for comparing fish versions
- Dominant language
- Rust
- Stars
- 34.2k
- Forks
- 2.4k
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 13
Description
There may already be a way to do this, but I haven't managed to find it.
I'm currently using fish 2.4.0 and 2.6.0 (on different machines). My configuration is common (version controlled) across multiple machines and sometimes there are new features made available in new versions of fish that I want to use but aren't available yet in the fish versions in one distro's package manager. In this case, it would be useful to have a robust way of comparing versions like python's `sys.hexversion`, so my config could include:
```fish
if testversion 0x02050000
# Stuff that relies on fish version 2.5 features
end
if testversion 0x03000000
# Stuff that relies on fish version 3.0 features
end
```
At the moment I've implemented this with:
```fish
function get_hexversion
set verparts (string split . $version)
while test (count $verparts) -lt 4
set verparts $verparts 0
end
echo "0x"(printf "%02x" $verparts[1])(printf "%02x" $verparts[2])(printf "%02x" $verparts[3])(printf "%02x" $verparts[4])
end
function testversion -a expectedhex
set -l expected (printf "%d" $expectedhex)
set -l actual (printf "%d" (get_hexversion))
return (test $actual -ge $expected)
end
```
However, it would be nice to have a built-in way of supporting this (although this obviously wouldn't work on existing released versions). There's probably a much better way of converting (e.g.) "2.6.0" into "0x02060000" than the way I've done it above (list comprehensions?), but this seems to work at the moment at least until I see what the version string looks like in 2.5b1 or whatever...
I guess it could be done at the moment with a `testversion` implementation that parses "2.6.0" directly, but I implemented it this way due to my familiarity with `sys.hexversion` in python.
Contributor guide
Assessment
This issue has not been assessed yet.