etc
ubuntu 터미널 현 디렉토리 우측에 git branch 출력
seoft
2019. 10. 7. 22:21
[문제정의]
다음과같이 ubuntu 터미널 현 디렉토리 우측에 git current branch 출력하기 위함
[해결방안]
0. 작업 환경
ubuntu16.04기준 (18.04도 확인완료)
mobaXterm client로 테스트
1. ~/.bashrc 파일의 가장 밑에 다음 코드를 덧붙임
# Show git branch name
force_color_prompt=yes
color_prompt=yes
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
fi
unset color_prompt force_color_prompt
2. 다음 명령어로 변경사항 적용
source ~/.bashrc
[적용사항 비교]
1~2줄 : 적용 전
3~4줄 : 적용 후
[Ref]
https://askubuntu.com/questions/730754/how-do-i-show-the-git-branch-with-colours-in-bash-prompt