Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current toolchain name for PS1 prompt #147

Open
aetherknight opened this issue Mar 19, 2016 · 0 comments
Open

Current toolchain name for PS1 prompt #147

aetherknight opened this issue Mar 19, 2016 · 0 comments

Comments

@aetherknight
Copy link
Contributor

I like to include profile information in my bash shell prompt about the current directory/project (eg, current git branch, rbenv ruby version, etc.). I would like to be able to indicate which multirust toolchain is currently active in a succinct fashion (eg, "nightly", "stable").

Currently, the only way to determine which toolchain would be run is to parse output from multirust show-override:

$ multirust show-override
multirust: override toolchain: nightly
multirust: override location: /Users/aetherkn/.multirust/toolchains/nightly
multirust: override reason: directory override for '/Users/aetherkn/src/rust/games-for-redox'

rustc 1.9.0-nightly (b12b4e4e3 2016-03-17)
cargo 0.10.0-nightly (ece4e96 2016-03-17)

I'm currently parsing it with something like:

    __rust_version() {
        test -r Cargo.toml || return # Detect a Rust project
        type -p multirust > /dev/null || return

        local v=""
        local overrideinfo=$(multirust show-override)
        local firstline=$(echo "${overrideinfo}" | head -n1)
        if [[ "$firstline" =~ "override toolchain:" ]] ; then
            v=${firstline#*override toolchain: }
        else
            local secondline=$(echo "${overrideinfo}" | head -n2 | tail -n1)
            v=${secondline#*default toolchain: }
        fi

        if [ ! -z "$v" ] ; then
            echo "|⚙ ${v}"
        fi
    }

However, this could be greatly simplified (and would be less brittle to changes in multirust's output) if multirust provided a sub-command or a flag to compute the the current toolchain name. It could also avoid calling rustc and cargo to get their versions. It could simplify to something like:

    __rust_version() {
        test -r Cargo.toml || return # Detect a Rust project
        type -p multirust > /dev/null || return

        local v=$(multirust show-toolchain)

        if [ ! -z "$v" ] ; then
            echo "|⚙ ${v}"
        fi
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant