Serach

2013년 10월 11일 금요일

git prompt 설정

ubuntu

다음의 내용을 ~/.bashrc 파일의 끝에 붙여넣는다.

# Configure colors, if available.
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
    c_reset='\[\e[0m\]'
    c_user='\[\e[0;32m\]'
    c_path='\[\e[1;34m\]'
    c_git_clean='\[\e[0;37m\]'
    c_git_staged='\[\e[0;32m\]'
    c_git_unstaged='\[\e[0;31m\]'
else
    c_reset=
    c_user=
    c_path=
    c_git_clean=
    c_git_staged=
    c_git_unstaged=
fi

# Add the titlebar information when it is supported.
case $TERM in
xterm*|rxvt*)
    TITLEBAR='\[\e]0;\u@\h: \w\a\]';
    ;;
*)
    TITLEBAR="";
    ;;
esac

# Function to assemble the Git parsingart of our prompt.
git_prompt ()
{
    GIT_DIR=`git rev-parse --git-dir 2>/dev/null`
    if [ -z "$GIT_DIR" ]; then
        return 0
    fi
    GIT_HEAD=`cat $GIT_DIR/HEAD`
    GIT_BRANCH=${GIT_HEAD##*/}
    if [ ${#GIT_BRANCH} -eq 40 ]; then
        GIT_BRANCH="(no branch)"
    fi
    STATUS=`git status --porcelain`
    if [ -z "$STATUS" ]; then
        git_color="${c_git_clean}"
    else
        echo -e "$STATUS" | grep -q '^ [A-Z\?]'
        if [ $? -eq 0 ]; then
            git_color="${c_git_unstaged}"
        else
            git_color="${c_git_staged}"
        fi
    fi
    echo "[$git_color$GIT_BRANCH$c_reset]"
}

# Thy holy prompt.
PROMPT_COMMAND="$PROMPT_COMMAND PS1=\"${TITLEBAR}${c_user}\u${c_reset}@${c_user}\h${c_reset}:${c_path}\w${c_reset}\$(git_prompt)\$ \" ;"





mac

~/.bash_profile 에 다음 내용을 복사한다.


# Custom git prompt
function __git_status() {
    local git_status="`git status -unormal 2>&1`"
    if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
        if [[ "$git_status" =~ nothing\ to\ commit ]]; then
            local ansi=32
        elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then
            local ansi=33
        else
            local ansi=35
        fi
        if [[ "$git_status" =~ On\ branch\ ([^[:space:]]+) ]]; then
            branch=${BASH_REMATCH[1]}
        else
            # Detached HEAD.  (branch=HEAD is a faster alternative.)
            branch="(`git describe --all --contains --abbrev=4 HEAD 2> /dev/null ||
                echo HEAD`)"
        fi
        echo -n '\[\e[0;'"$ansi"'m\]'"($branch)"
    fi
}
function __git_prompt() {
    ps1pc_start="$1"
ps1pc_end="$2"
ps1git=`__git_status`
    PS1="$ps1pc_start$ps1git$ps1pc_end"
}

#PS1="\[\e[0;32m\]\u@\h:\[\e[0;34m\]\w\$ \[\e[0m\]"

PROMPT_COMMAND='update_terminal_cwd;__git_prompt "\[\e[0;32m\]\u@\h:\[\e[0;34m\]\w " "\[\e[0;34m\]\$ \[\e[0m\]"'

export PATH=$PATH:~/bin
export CLICOLOR=yes
export TERM=xterm-color
#export LESS=X
#if [ -z $DISPLAY ]; then export DISPLAY=":0.0"; fi    # Enable X11 tunneling through ssh
#alias ssh='ssh -Y'                                    # force X11 tunneling through ssh

# Set variable for GTest
export GTEST_COLOR=yes

# Git auto-completion
source ~/.git-completion.bash

# Resize open files
ulimit -n 8192



댓글 없음:

댓글 쓰기