romkatv / powerlevel10k

A Zsh theme
MIT License
46.6k stars 2.19k forks source link

Rustc version doesn't update #418

Closed Aloxaf closed 4 years ago

Aloxaf commented 4 years ago

图片

This seems to have been fixed in #365. But it only works if the rustc is installed by the system package manager. If I use rustup to manage different versions of rust toolchains, it won't work.

Here is some information:

❯ file =rustc
/usr/bin/rustc: symbolic link to /usr/bin/rustup
❯ ldd =rustc
        linux-vdso.so.1 (0x00007ffcdcd96000)
        liblzma.so.5 => /usr/lib/liblzma.so.5 (0x00007fe1f5647000)
        libssl.so.1.1 => /usr/lib/libssl.so.1.1 (0x00007fe1f55b7000)
        libcrypto.so.1.1 => /usr/lib/libcrypto.so.1.1 (0x00007fe1f52e6000)
        libcurl.so.4 => /usr/lib/libcurl.so.4 (0x00007fe1f5259000)
        libdl.so.2 => /usr/lib/libdl.so.2 (0x00007fe1f5254000)
        libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007fe1f5232000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007fe1f5216000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007fe1f504f000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007fe1f4f09000)
        libnghttp2.so.14 => /usr/lib/libnghttp2.so.14 (0x00007fe1f4ee1000)
        libidn2.so.0 => /usr/lib/libidn2.so.0 (0x00007fe1f4ec0000)
        libssh2.so.1 => /usr/lib/libssh2.so.1 (0x00007fe1f4e80000)
        libpsl.so.5 => /usr/lib/libpsl.so.5 (0x00007fe1f4e6b000)
        libgssapi_krb5.so.2 => /usr/lib/libgssapi_krb5.so.2 (0x00007fe1f4e1b000)
        libkrb5.so.3 => /usr/lib/libkrb5.so.3 (0x00007fe1f4d2e000)
        libk5crypto.so.3 => /usr/lib/libk5crypto.so.3 (0x00007fe1f4cfa000)
        libcom_err.so.2 => /usr/lib/libcom_err.so.2 (0x00007fe1f4cf4000)
        libz.so.1 => /usr/lib/libz.so.1 (0x00007fe1f4cda000)
        /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007fe1f5d7e000)
        libunistring.so.2 => /usr/lib/libunistring.so.2 (0x00007fe1f4b56000)
        libkrb5support.so.0 => /usr/lib/libkrb5support.so.0 (0x00007fe1f4b47000)
        libkeyutils.so.1 => /usr/lib/libkeyutils.so.1 (0x00007fe1f4b40000)
        libresolv.so.2 => /usr/lib/libresolv.so.2 (0x00007fe1f4b27000)

BTW. I suggest (adding an option?) showing the date of the nightly version, because many projects depend on a specific nightly version, like remacs, tikv. It will be helpful If I can confirm whether I am using the right version from PROMPT info.

Aloxaf commented 4 years ago

Rustup will change ~/.rustup/settings.toml when I change the default rust toolchain version. Here is its content on my system:

default_toolchain = "nightly-x86_64-unknown-linux-gnu"
version = "12"

[overrides]

And if I update the toolchain, ~/.rustup/update-hashes/nightly-x86_64-unknown-linux-gnu will be updated:

❯ cat ~/.rustup/update-hashes/nightly-x86_64-unknown-linux-gnu
74e88a41126c2cfb904b

Maybe should check whether a user is using rustup or just a rustc installed by the system package manager, then use different way to get the version?

romkatv commented 4 years ago

Thanks for the bug report and super valuable insights. I'm on it.

romkatv commented 4 years ago

I added support for rustup. All types of toolchain overrides should work:

In all cases p10k shows the same rust version as rustc --version.

The implementation is a bit slower than I'd like (about 0.6 ms on my machine) but it'll do for now. I'll get back to it when I consolidate stat calls for parent directories.

I also added P9K_RUST_VERSION. Like other P9K_* parameters, this one is set by p10k (users of p10k set POWERLEVEL9K_* parameters). It contains the full output of rustc --version and you can use it in POWERLEVEL9K_RUST_VERSION_CONTENT_EXPANSION. For example:

typeset -g POWERLEVEL9K_RUST_VERSION_CONTENT_EXPANSION='${P9K_RUST_VERSION#rustc }'

If you've never used *_CONTENT_EXPANSION before, it overrides the content of a prompt segment. The original content is available in $P9K_CONTENT so that you can patch it if desired. You can use percent escapes there, too.

# The same as the default but bold and bracketed.
typeset -g POWERLEVEL9K_RUST_VERSION_CONTENT_EXPANSION='%B[$P9K_CONTENT]%b'

Let me know if this works for you.

Aloxaf commented 4 years ago

Thanks for your quick fix! POWERLEVEL9K_RUST_VERSION_CONTENT_EXPANSION is awesome!

There is still a small bug: https://github.com/romkatv/powerlevel10k/blob/1cf99b34e550e0294cb5d300bbf5b4eb331687aa/internal/p10k.zsh#L2374 Here $rustc will be expanded to rustup, so $rustc --version will only get rustup version. Change it to rustc --version then everything works. ( just a personal try, not sure if it can be a real solutoin

romkatv commented 4 years ago

Fixed.

FWIW, my installation of rustup uses hard links. This makes sense. Using symlinks and together with dispatch by argv[0] is crazy. Perhaps they've fixed it?

Thanks for reporting the issue and for testing my fixes!

romkatv commented 4 years ago

By the way, before you invest into heavy customization of ~/p10k.zsh, consider switching to Lean style.

Aloxaf commented 4 years ago

It works, thanks for your great work!

I installed rustup by the system package manager. Maybe this is an OS-specific problem? (My OS is Arch Linux)

Thanks for your advice. I'm just new to p10k and is exploring it.

romkatv commented 4 years ago

Thanks for your advice. I'm just new to p10k and is exploring it.

Welcome aboard! If you feel like trying bleeding edge (but very cool!) features, check out https://github.com/romkatv/powerlevel10k/issues/318. Maybe this could be useful for rust, too? For example, you could configure p10k to display rust version only when your current command (the one you are still typing) invokes rustc. Or perhaps display it if there is Cargo.toml in one of the parent directories OR the current command is rustc? Basically, if you can come up with cool ideas of what prompt should do, I can implement them. I'm hardly using any of the technologies that p10k users use, so I rely on others to educate me.

arch-user-france1 commented 3 years ago

still doesn't work

romkatv commented 3 years ago

@debian-user-france1 If something doesn't work for you, please open an issue.