文章

备份:Ubuntu Bash Alias, 以及 bash 显示 git status

bash alias

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
###################
# bash alias
alias g='git status -sb'

alias ll='ls -alF'
alias la='ls -A'
alias l='ls -ltrhA'
alias gl='ls|grep --color'
# alias .='cd ../'
# alias ..='cd ../..'
alias ..='cd ..'
alias ...='cd ..; cd ..'
alias ....='cd ..; cd ..; cd ..'

alias c='clear'
alias r='reset'

bash 显示 git status

1
2
3
4
5
6
7
8
9
10
11
12
# 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

参考:How do I show the git branch with colours in Bash prompt?

本文由作者按照 CC BY 4.0 进行授权