0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mac terminal コマンドプロンプトにgit のブランチを表示

Posted at

git のterminal 、teraterm コマンドプロンプトの表示を変える

デフォルトではterminalなどのコマンドプロンプトは下記のような感じなっております。

スクリーンショット 2017-07-30 19.55.18.png

こちらをわかりやすいように色分けしたり、git のブランチを表示させたりします。

下記のような感じになります。

スクリーンショット 2017-07-30 20.01.55.png

このような状態にするには下記bash を  ~/.bash_profile に記述しsource で反映させるとこのような感じになります。

下記手順になります。

vi ~/.bash_profile
function parse_git_branch {
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ [\1]/'
}
function promps {
    local  BLUE="\[\e[1;34m\]"
    local  RED="\[\e[1;31m\]"
    local  GREEN="\[\e[1;32m\]"
    local  WHITE="\[\e[00m\]"
    local  GRAY="\[\e[1;37m\]"
    local  Mag="\[\e[1;35m\]"
    local  LIGHT_B="\[\e[0;34m\]"
    local  LIGHT_GREEN="\[\e[0;36m\]"
    case $TERM in
        xterm*) TITLEBAR='\[\e]0;\W\007\]';;
        *)      TITLEBAR="";;
    esac
    local BASE="\u@\h"
#    PS1="${TITLEBAR}${GREEN}${BASE}${WHITE}:${BLUE}\W${GREEN}\$(parse_git_branch)${BLUE}\$${WHITE} "

     PS1="${LIGHT_GREEN}\u${GREEN}\w:${GREEN}\$(parse_git_branch)${BLUE}\$${WHITE}: \n->> "
}
promps

色の名前はなんとなくつけたものなので、ご自分のお好きなように変更されると良いかと思われます。

ho

設定 内容
\h ホスト名 あなたのMacの名前 (システム環境設定>ユーザとグループ>ユーザ右クリックで編集可能)
\u ユーザ名 ログインユーザーの名前同上
\w 現在のディレクトリ※フルパス ~/Applications
\W 現在のディレクトリ Applications
\t 現在時刻※24時間表記 17:14:42
\T 現在時刻 ※12時間表記 05:14:42
\d 日付と曜日※ダサいから注意 日 7 27

色の設定

コード
\[\033[30m]色付けたい部分[\033[0m] Black
[\033[31m]色付けたい部分[\033[0m] Red
[\033[32m]色付けたい部分[\033[0m] Green
[\033[33m]色付けたい部分[\033[0m] Yellow
[\033[34m]色付けたい部分[\033[0m] Blue
[\033[35m]色付けたい部分[\033[0m] Mangenta
[\033[36m]色付けたい部分[\033[0m] Cyan
[\033[37m]色付けたい部分[\033[0m] White

色の種類は下記にもあります。

bash_color.png

下記サイトから引用

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?