You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
952 B
Bash

parse_git_branch() {
if [ $(git status --porcelain 2> /dev/null | wc -l) != "0" ]; then
color=$'\001\e[31m\002'
elif [ $(git rev-list HEAD@{upstream}..HEAD 2> /dev/null | wc -l) != "0" ]; then
color=$'\001\e[33m\002'
else
color=$'\001\e[32m\002'
fi
reset=$'\001\e[0m\002'
git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/(${color}\1${reset}) /"
}
green=$(tput setaf 2)
reset=$(tput sgr0)
export PROMPT_DIRTRIM=2 # Trimming path to 2 directories
export PROMPT_PATH="[\[$green\]\w\[$reset\]] "
alias fullpath='export PROMPT_DIRTRIM=0; export PROMPT_PATH="[\[$green\]\w\[$reset\]] "; re_export_ps1'
alias partialpath='export PROMPT_DIRTRIM=2; export PROMPT_PATH="[\[$green\]\w\[$reset\]] "; re_export_ps1'
alias lastpath='export PROMPT_PATH="[\[$green\]\W\[$reset\]] "; re_export_ps1'
alias nopath='export PROMPT_PATH=; re_export_ps1'
re_export_ps1() {
export PS1="$PROMPT_PATH\$(parse_git_branch)\$ "
}
re_export_ps1