-
-
Save CrBoy/907528 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _ps1_git(){ | |
local ref cnt branch clean | |
ref=$(git symbolic-ref HEAD 2> /dev/null) | |
cnt=$(git branch 2> /dev/null|grep -c -E '*') | |
branch=$(echo "${ref#refs/heads/}") | |
if [[ "${branch}" == "" ]] | |
then | |
return | |
fi | |
local c1 c2 c3 c4 l1 l2 l3 l4 tmpfile | |
tmpfile=$(mktemp) | |
git status 2> /dev/null > ${tmpfile} | |
l1= | |
l2= | |
l3= | |
l4= | |
c1=$(grep -E '^# Changed but not updated' ${tmpfile}) | |
c2=$(grep -E '^# Untracked files' ${tmpfile}) | |
c3=$(grep -E '^#[[:space:]]+unmerged:' ${tmpfile}) | |
c4=$(grep -E '^# Changes to be committed' ${tmpfile}) | |
if [[ "$c1" != "" ]] | |
then | |
l1=M | |
fi | |
if [[ "$c2" != "" ]] | |
then | |
l2=U | |
fi | |
if [[ "$c3" != "" ]] | |
then | |
l3=C | |
fi | |
if [[ "$c4" != "" ]] | |
then | |
l4=A | |
fi | |
clean=${l4}${l1}${l2}${l3} | |
rm -f ${tmpfile} | |
echo -n '-' | |
echo -n $'\e[4;33m' | |
echo -n ${branch} | |
echo -n $'\e[m[\e[1;36m' | |
echo -n ${cnt}${clean} | |
echo -n $'\e[m]' | |
} | |
function _ps1_swap(){ | |
free -m|grep "Mem:"|awk '{print $4}' | |
} | |
export PS1='-[\e[1;31m\w\e[m]$(_ps1_git)-[$(_ps1_swap)]-[\e[1;31m\t\e[m]\n-\u@\h\$ ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment