From 342af2237bb714fb0e7739eff6a420b71e870bdf Mon Sep 17 00:00:00 2001 From: Vladan Popovic Date: Sun, 15 Dec 2019 01:42:11 +0100 Subject: [PATCH] Use one function for parsing SCM branch --- .bashrc | 2 +- .functions | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.bashrc b/.bashrc index fa271f0..b863493 100644 --- a/.bashrc +++ b/.bashrc @@ -14,7 +14,7 @@ source ~/.aliases source ~/.bashcolors source ~/.functions -export PS1="${Yellow}\d \A ${Off}${Cyan}\u@\h: ${Off}\w ${Green}\$(parse_git_branch)${BPurple}\$(parse_fossil_branch)${Off}\n-$ " +export PS1="${Yellow}\d \A ${Off}${Cyan}\u@\h: ${Off}\w ${Green}\$(parse_branch git)${BPurple}\$(parse_branch fossil)${Off}\n-$ " export PYTHONDONTWRITEBYTECODE=1 export PYTHONUSERBASE=~/.env/python diff --git a/.functions b/.functions index 42588b0..4b66cd3 100644 --- a/.functions +++ b/.functions @@ -2,12 +2,9 @@ iploc () { curl -s http://ip-api.com/json/"$1"|tr , '\n'|sed 's/[\"{}]//g'; } -function parse_git_branch () { - git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' -} - -function parse_fossil_branch () { - fossil branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' +function parse_branch { + scmexe=${1:-git} + $scmexe branch 2> /dev/null | awk '/^*/{print "("$2")"}' } yell() { echo "$0: $*" >&2; }