From 0520ab0de25774a8f690c8a51c2e7bc37aeb4edc Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 21 Sep 2013 18:16:07 +1200 Subject: Enhance parsing of hg status a bit too --- bash/bashrc.d/prompt.bash | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'bash') diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index cc750934..e2dfdc87 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -108,11 +108,24 @@ prompt() { # Start collecting working copy state flags local -a state - # If there are changes in the tree, add an exclamation mark to the - # state - if [[ $(hg status 2>/dev/null) ]]; then + # Safely read status from ``git porcelain'' + local line modified untracked + while IFS= read -d $'\0' -r line _; do + if [[ $line == '?'* ]]; then + untracked=1 + else + modified=1 + fi + done < <(hg status -0 2>/dev/null) + + # Build state array from status output flags + local -a state + if [[ $modified ]]; then state=("${state[@]}" '!') fi + if [[ $untracked ]]; then + state=("${state[@]}" '?') + fi # Print the status in brackets with an hg: prefix local IFS= -- cgit v1.2.3