Skip to content

ijanos/rustup_prompt_helper

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 

rustup prompt helper

A small command line utility that prints the name of the selected rust toolchain for the current working directory. It helps creating informative command line prompts or scripts where the alternative is piping the output of rustup command through other tools. While that approach is fine it is slower and if you have a busy prompt it can create a noticeable delay every time you press enter.

The output of rustup_prompt_helper should be identical to the following command, as of rustup version 1.0.0

rustup show | tail -n 3 | head -n 1 |  cut -d '-' -f 1

Example usage

You can install rustup_prompt_helper with the cargo. Make sure that cargo's binary directory is part of your PATH environment variable.

cargo install rustup_prompt_helper

bash

Here is simple bash prompt example. Place it in your ~/.bashrc and it will show the currently selected toolchain in the prompt if the directory contains a Cargo.toml file.

function rust_toolchain {
   if [ -f Cargo.toml ]; then
      echo " [rust:$(rustup_prompt_helper)]"
   fi
}

PS1='[\u@\h \W]$(rust_toolchain) \$ '

fish

Fish shell uses the fish_prompt function to create a prompt. It can be customized by creating a .config/fish/functions/fish_prompt.fish file.

For a complete example see my fish prompt config.

Handling errors

All errors are silenced by default. If an error happens the program will simply exit without printing anything. While error silencing is generally not the greatest idea, this program's output should be printed directly into shell prompts and spilling a large error message into a prompt can cause all kinds of trouble.

To see error messages simply pass any argument to the tool like -debug for example.

License

Licensed under either of

at your option.

About

print the active rustup toolchain for the current working directory

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages