improved git branch status
This commit is contained in:
parent
03c1867fb9
commit
377f40ceca
2 changed files with 63 additions and 50 deletions
49
.bash_prompt
Normal file
49
.bash_prompt
Normal file
|
@ -0,0 +1,49 @@
|
|||
# defines __git_ps1
|
||||
if [ -f ~/.bash_git ]; then
|
||||
GIT_PS1_SHOWCOLORHINTS=1
|
||||
GIT_PS1_SHOWDIRTYSTATE=1
|
||||
GIT_PS1_SHOWSTASHSTATE=1
|
||||
GIT_PS1_SHOWUNTRACKEDFILES=1
|
||||
GIT_PS1_SHOWUPSTREAM="auto"
|
||||
|
||||
source ~/.bash_git
|
||||
|
||||
PROMPT_COMMAND=show_prompt
|
||||
fi
|
||||
|
||||
cnt=0
|
||||
|
||||
function show_prompt {
|
||||
# Time
|
||||
local pre='\[\e[01;30m\]\A '
|
||||
local post
|
||||
|
||||
# Check last return value
|
||||
if [[ $? -eq 0 ]]; then
|
||||
pre+='\[\e[32m\]✔ '
|
||||
else
|
||||
pre+='\[\e[31m\]✘ '
|
||||
fi
|
||||
|
||||
# Test if root
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
pre+='\[\e[01;34m\]\u\[\e[01;33m\]@\[\e[01;36m\]\H'
|
||||
post='\[\e[01;34m\]\w'
|
||||
else
|
||||
pre+='\[\e[31m\]\u\[\e[01;33m\]@\[\e[01;36m\]\H'
|
||||
post='\[\e[01;33m\]\w'
|
||||
fi
|
||||
|
||||
post+='\n \[\e[01;30m\]\# \[\e[31m\]\$ \[\e[00m\]'
|
||||
|
||||
__git_ps1 "$pre " "$post" '\[\e[01;30m\](%s\[\e[01;30m\]) '
|
||||
}
|
||||
|
||||
# If this is an xterm set the title to user@host:dir
|
||||
case "$TERM" in
|
||||
xterm*|rxvt*)
|
||||
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
64
.bashrc
64
.bashrc
|
@ -4,17 +4,6 @@
|
|||
# If not running interactively, don't do anything
|
||||
[ -z "$PS1" ] && return
|
||||
|
||||
# don't put duplicate lines or lines starting with space in the history.
|
||||
# See bash(1) for more options
|
||||
HISTCONTROL=ignoreboth
|
||||
|
||||
# append to the history file, don't overwrite it
|
||||
shopt -s histappend
|
||||
|
||||
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
|
||||
HISTSIZE=99999999
|
||||
HISTFILESIZE=99999999
|
||||
|
||||
# check the window size after each command and, if necessary,
|
||||
# update the values of LINES and COLUMNS.
|
||||
shopt -s checkwinsize
|
||||
|
@ -23,34 +12,26 @@ shopt -s checkwinsize
|
|||
# match all files and zero or more directories and subdirectories.
|
||||
shopt -s globstar
|
||||
|
||||
# make less more friendly for non-text input files, see lesspipe(1)
|
||||
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
|
||||
# append to the history file, don't overwrite it
|
||||
shopt -s histappend
|
||||
|
||||
# don't put duplicate lines or lines starting with space in the history.
|
||||
# See bash(1) for more options
|
||||
HISTCONTROL=ignoreboth
|
||||
|
||||
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
|
||||
HISTSIZE=99999999
|
||||
HISTFILESIZE=99999999
|
||||
|
||||
# set variable identifying the chroot you work in (used in the prompt below)
|
||||
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
|
||||
debian_chroot=$(cat /etc/debian_chroot)
|
||||
fi
|
||||
|
||||
# defines __git_ps1
|
||||
if [ -f ~/.bash_env ]; then
|
||||
source ~/.bash_git
|
||||
fi
|
||||
|
||||
# command prompt
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
PS1='\[\e[01;30m\]\A `if [ $? = 0 ]; then echo "\[\e[32m\]✔"; else echo "\[\e[31m\]✘"; fi` \[\e[01;34m\]\u\[\e[01;33m\]@\[\e[01;36m\]\h `[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "\[\e[31m\]" || echo "\[\e[32m\]"`$(__git_ps1 "(%s)\[\e[00m\]")\[\e[01;34m\]\w\[\e[00m\]\$ '
|
||||
else
|
||||
PS1='\[\e[01;30m\]\A `if [ $? = 0 ]; then echo "\[\e[32m\]✔"; else echo "\[\e[31m\]✘"; fi` \[\e[31m\]\u\[\e[01;33m\]@\[\e[01;36m\]\h \[\e[33m\]\w\[\e[31m\]\$\[\033[00m\] '
|
||||
fi
|
||||
|
||||
# If this is an xterm set the title to user@host:dir
|
||||
case "$TERM" in
|
||||
xterm*|rxvt*)
|
||||
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
# Include more scripts
|
||||
if [ -f ~/.bash_aliases ]; then source ~/.bash_aliases; fi
|
||||
if [ -f ~/.bash_env ]; then source ~/.bash_env; fi
|
||||
if [ -f ~/.bash_prompt ]; then source ~/.bash_prompt; fi
|
||||
|
||||
# enable color support of ls and also add handy aliases
|
||||
if [ -x /usr/bin/dircolors ]; then
|
||||
|
@ -61,20 +42,3 @@ if [ -x /usr/bin/dircolors ]; then
|
|||
alias fgrep='fgrep --color=auto'
|
||||
alias egrep='egrep --color=auto'
|
||||
fi
|
||||
|
||||
# Alias definitions
|
||||
if [ -f ~/.bash_aliases ]; then
|
||||
. ~/.bash_aliases
|
||||
fi
|
||||
|
||||
# Environment
|
||||
if [ -f ~/.bash_env ]; then
|
||||
source ~/.bash_env
|
||||
fi
|
||||
|
||||
# enable programmable completion features (you don't need to enable
|
||||
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
|
||||
# sources /etc/bash.bashrc).
|
||||
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
|
||||
. /etc/bash_completion
|
||||
fi
|
||||
|
|
Loading…
Add table
Reference in a new issue