0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

bashプロンプトをカスタムしてGitブランチを表示させる

Posted at

bashプロンプトにGitブランチを表示させる

# 現在のブランチ名を取得する関数
function parse_git_branch {
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

# プロンプトカスタマイズ用の関数
function prompts {
    # 色は気分で変えたいかもしれないので変す宣言しておく
    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  FG_WHITE_BG_GREEN_BOLD="\[\e[1;37;42m\]"
    local  FG_GREEN_BG_WHITE="\[\e[0;32;47m\]"
    local  FG_BLACK_BG_WHITE="\[\e[30;47m\]"
    local  FG_WHITE_BG_CYAN="\[\e[37;46m\]"
    local  FG_BLACK_BG_CYAN="\[\e[30;46m\]"
    local  FG_CYAN_BG_BLACK="\[\e[0;36m\]"


    case $TERM in
        xterm*) TITLEBAR='\[\e]0;\W\007\]';;
        *)      TITLEBAR="";;
    esac
    local BASE="\u"
    export PS1="${FG_WHITE_BG_GREEN_BOLD} ${BASE} ${FG_GREEN_BG_WHITE}${FG_BLACK_BG_WHITE} \W ${FG_WHITE_BG_CYAN}${FG_BLACK_BG_CYAN}\$(parse_git_branch) ${FG_CYAN_BG_BLACK} \[\e[0m\]"

}

# 関数実行
prompts

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?