0
これはほとんどの場合、gitステータスに基づいてbashプロンプトに色を追加できました。すべてがコミットされていれば、(origin/master)は緑色になります。そうでなければ、コミットしていないことがわかります。しかし、私は追加の色を追加しようとしている、黄色のような '未変更の変更'と赤い私は何もしていない場合。ここで ほとんどそこに! bashプロンプトに別のgitステータスカラーを追加するにはどうすればいいですか?
は私が私の.bashrcに様々な記事から、これまで一緒に石畳てきたものだバッシュバージョン:-release 4.3.48(1)
OS:Linuxのミント18.2
## trim to two dir depth
PROMPT_DIRTRIM=2
## green [email protected], then blue dirs, then colours for git branch
COLOURGREEN="\033[01;32m"
COLOURBLUE="\033[01;34m"
COLOURPLAIN="\033[m"
COLOURRED="\033[1;31m"
COLOURYELLOW="\033[1;33m"
## This works fine on it's own, I see the (origin/master) in prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
## green works when all files committed but not other colours
git_colour() {
local gitstatus="$(git status 2> /dev/null)"
if [[ ! $gitstatus =~ "working directory clean" ]]; then
echo -e $COLOURRED
elif [[ $gitstatus =~ "Untracked files:" ]]; then
echo -e $COLOURYELLOW
elif [[ $gitstatus =~ "nothing to commit" ]]; then
echo -e $COLOURGREEN
else
echo -e $COLOURPLAIN
fi
}
## working export without colour on git
# Example: [email protected] ~/.../dir3/dir4 (origin/master)
# export PS1="\[\033[01;32m\]\[email protected]\h\[\033[01;34m\] \w\[\033[m\]\$(parse_git_branch) $ "
## works only when green
export PS1="\[\033[01;32m\]\[email protected]\h\[\033[01;34m\] \w\[\$(git_colour)\]\$(parse_git_branch)\[\033[m\] $ "
git_colour()のほんの少しの助けを借りているのですか、またはbashのカラーコードを使い果たしたのですか?ありがとう
ステータスが "作業ディレクトリのクリーン"以外の場合は、赤くなりますか? –
いいえ清潔な場合は緑色になり、それ以外の場合は緑色になります。他の色は発生しません。私は見てgitステータスのさまざまな状態を試みているが、完全にコミットされた状態だけがdirを緑にします。 – sf2k
私はifステートメントを減らし、何が起こっているのかを確認するために再構築しようとしています – sf2k