starship: Allow Elixir module to use `elixir --short-version` because `elixir --version` is very slow

Feature Request

Is your feature request related to a problem? Please describe.

Requesting the Elixir version can take upwards of 700ms, because elxiir --version starts the entire VM. This can cause the prompt to frequently timeout or seem very slow.

Describe the solution you’d like

Since Elixir v 1.13.0 there is a --short-version switch. This doesn’t start the VM and returns results in less than 10ms, but it can only show the full version of Elixir and not OTP. It would be nice if there was a way to make use of this.

The most complex but exhaustive option would be:

  if format configuration does NOT contain "$otp_version"
  and the elixir value from the mix.exs file (e.g. elixir: "~>1.13") and that version 1.13 or greater
  then use the `--short-version` command

Alternatively simply providing a configuration switch that uses elxiir --short-version, but that would have to come with caveats that it will fail on versions older than 1.13 and will not provide the OTP version.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 18 (1 by maintainers)

Most upvoted comments

My custom script just in case someone find it useful:

[custom.elixir]
format = '[$symbol(v$output )]($style)'
command = "elixir --short-version 2>/dev/null || (elixir --version | grep '^Elixir' | awk '{print $2}')"
when = "test -f mix.exs"
style = 'bold purple'
symbol = '💧 '

It uses --short-version and if that’s not working then it will use --version. It may be slower for old versions, so I guess use it if most of your projects are running 1.13+

[custom.asdf_elixir]
command = """asdf current elixir | awk '{print $2}' | awk -F'-' '{print "v"$1" (OTP "$3")"}'"""
detect_files = ["mix.exs"]
format = "💧 [$output]($style)"
style = "bold purple"
 Here are the timings of modules in your prompt (>=1ms or output):
 elixir       -  445ms  -   "via 💧 v1.14.0 (OTP 25) "
 asdf_elixir  -  187ms  -   "💧 v1.14.0 (OTP 25)"
 character    -   <1ms  -   "❯ "

❯                                           via 💧 v1.14.0 (OTP 25) 💧 v1.14.0 (OTP 25)

also pasted the custom elixir config to get elixir and otp version from asdf

Nice find!

This looks like you are relying on the path containing the otp version using type elixir. It looks like this install script installs both Erlang and Elixir, which means it can put both versions in the path.

I think most tools like apt, pacman, brew, etc and version managers ike asdf, mise, etc all expect Erlang as a separately installed package. So the path alone doesn’t really have any information about the OTP version or potentially even the version of Elixir. Before the addition of --short-version the only reliable way to get the version was to run elixir -v which starts the whole VM just to print the version string.