Sketch: #3
Good Git Prompt
General |
Video List |
Video Latest |
Carousel |
Carousel Recent |
D&D 5e |
Fantasy Grounds |
Insult |
Secrets |
Sketches |
Sensor Readings
I need to work on the formatting of the code block, but the base is there for now.
-- This makes git from command prompt easier to deal with.
# .bashrc
# User specific aliases and functions
alias dcu='echo "all your dockers are belong to us"'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
COLOR_RED="\033[0;31m"
COLOR_BOLD_RED="\033[1;31m"
COLOR_YELLOW="\033[0;33m"
COLOR_BOLD_YELLOW="\033[1;33m"
COLOR_GREEN="\033[0;32m"
COLOR_BOLD_GREEN="\033[1;32m"
COLOR_OCHRE="\033[38;5;95m"
COLOR_BLUE="\033[0;34m"
COLOR_WHITE="\033[0;37m"
COLOR_BOLD_WHITE="\033[1;37m"
COLOR_RESET="\033[0m"
git_branch() {
git branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/ '
}
git_status() {
local status="$(git status --porcelain 2>/dev/null)"
local output=''
[[ -n $(egrep '^[MADRC]' <<<"$status") ]] && output="$output+"
[[ -n $(egrep '^.[MD]' <<<"$status") ]] && output="$output!"
[[ -n $(egrep '^\?\?' <<<"$status") ]] && output="$output?"
[[ -n $(git stash list) ]] && output="${output}S"
[[ -n $(git log --branches --not --remotes) ]] && output="${output}P"
[[ -n $output ]] && output="|$output"
echo $output
}
git_color() {
local staged=$([[ $1 =~ \+ ]] && echo yes)
local dirty=$([[ $1 =~ [!\?] ]] && echo yes)
if [[ -n $staged ]] && [[ -n $dirty ]]; then
echo -e $COLOR_BOLD_YELLOW
elif [[ -n $staged ]]; then
echo -e $COLOR_BOLD_GREEN
elif [[ -n $dirty ]]; then
echo -e $COLOR_BOLD_RED
else
echo -e $COLOR_BOLD_WHITE
fi
}
git_prompt() {
local branch=$(git_branch)
if [[ -n $branch ]]; then
local state=$(git_status)
local color=$(git_color $state)
echo -e "\x01$color\x02[$branch$state]\x01\033[00m\x02"
fi
}
export PS1='$debian_chroot\[\033[0;32m\]\u@\h\[\033[00m\]:\[\033[38;5;215m\]\W$(git_prompt)\[\033[00m\]\$ '