From ad9a5431840505ce6baca7861058eaa75baab077 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 27 Aug 2021 11:30:52 +0100 Subject: Functions to support useful prompts --- bashrc | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/bashrc b/bashrc index 3580770..abf2988 100644 --- a/bashrc +++ b/bashrc @@ -170,6 +170,63 @@ showdiff() { local feat=${1-HEAD} target=${2-origin/master} diffWith "git diff $target...$feat -w -D -M --patience --find-copies-harder" } +style_reset() { + echo -ne "\001\e[0m\002" +} +style_set() { + echo -ne "\001\e[${1};${2}m\002" +} +style_message() { + echo -ne " $(style_set $1 $2)$3$(style_reset)" +} +git_prompt() { + local branchname=$(git branch --show-current 2> /dev/null) + if [[ -n $branchname ]]; then + local detail=$(git branch --list $branchname -v 2> /dev/null) + local status=$(git status --porcelain 2> /dev/null) + local style=00 + local color=92 + if [[ $detail =~ ahead\ [0-9] ]]; then + if [[ $detail =~ behind\ [0-9] ]]; then + style=05 + else + style=03 + fi + elif [[ $detail =~ behind\ [0-9] ]]; then + style=04 + fi + if [[ -n $status ]]; then + color=96 + fi + style_message $style $color $branchname + fi +} +bjam_prompt() { + if [[ -f Jamfile.jam || -f Jamroot.jam ]]; then + local updates=$(bjam -nd1 | sed -n 's/^\.\.\.updated \([0-9]\+\) targets\.\.\.$/\1/p') + if [[ -n $updates ]]; then + style_message 01 31 $updates + fi + fi +} +result_prompt() { + case $1 in + 0) + style_message 00 32 ✔ + ;; + "") + style_message 01 34 $ + ;; + *) + style_message 01 91 ✘ + ;; + esac +} +prompts() { + local res=$? + git_prompt + result_prompt $res +} gppdmb() { PARENT=${1:-master} git checkout $PARENT && git pull --prune && git delete-merged-branches -- cgit v1.2.3