LoginSignup
3
3

More than 5 years have passed since last update.

Zsh環境で雑にRustプロジェクトのディレクトリかどうかを判断してrustcのバージョンを表示する

Last updated at Posted at 2017-06-09

zsh-rust-version.png

カレントディレクトリに Cargo.tomlが存在したら、rustc --version実行して、プロンプトに出力するという感じです。ごちゃごちゃと別の設定も入ってますが、キモはprecmd()あたりです。
雑なのであとはご自身でいい感じにしてみてください。

setopt prompt_subst
local GREEN=$'%{\e[1;38;5;202m%}'
local PINK=$'%{\e[1;38;5;198m%}'
local LGREEN=$'%{\e[1;38;5;149m%}'
local YELLOW=$'%{\e[1;38;5;33m%}'
local BLUE=$'%{\e[1;34m%}'
local DEFAULTNON=$'%{\e[1;0m%}'
local DEFAULT=$'%{\e[1;38;5;152m%}'
autoload -Uz vcs_info
zstyle ':vcs_info:*' formats '(%s)-[%b]'
zstyle ':vcs_info:*' actionformats '(%s)-[%b|%a]'
precmd () {
    psvar=()
    LANG=en_US.UTF-8 vcs_info
    [[ -n "$vcs_info_msg_0_" ]] && psvar[1]="$vcs_info_msg_0_"
    if [ -e ./Cargo.toml ]; then
        PROMPT_RUSTC_VERSION=" rust:"$BLUE`rustc --version | awk '{ print $2 }'`$DEFAULTNON
    else
        PROMPT_RUSTC_VERSION=""
    fi
}
PROMPT='[%D.%T]'$GREEN'%n@%m: '$YELLOW'%(5~,%-2~/../%2~,%~) '$DEFAULTNON'%1(v|'$LGREEN'%1v%f|)'$DEFAULTNON'$PROMPT_RUSTC_VERSION'$'\n'$DEFAULTNON'%(!.#.$) '
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3