From 66b4a94bdf35f658ca7256cd98420dca24a30d91 Mon Sep 17 00:00:00 2001 From: DrVanScott Date: Sun, 17 Jul 2016 16:57:17 +0200 Subject: [PATCH 1/3] rewrite bash 4 ;;& operator --- gitstatus.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 8dcd49b..e305990 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -26,15 +26,18 @@ num_conflicts=0 num_untracked=0 while IFS='' read -r line || [[ -n "$line" ]]; do status=${line:0:2} - case "$status" in - \#\#) branch_line="${line/\.\.\./^}" ;; - ?M) ((num_changed++)) ;;& - ?D) ((num_changed++)) ;;& - U?) ((num_conflicts++)) ;;& - \?\?) ((num_untracked++)) ;; - \ ?) ;; - *) ((num_staged++)) ;; - esac + while true + do + case "$status" in + \#\#) branch_line="${line/\.\.\./^}"; break ;; + ?M) ((num_changed++)); status=${status:0:1}"_" ;; + ?D) ((num_changed++)); status=${status:0:1}"_" ;; + U?) ((num_conflicts++)); break ;; + \?\?) ((num_untracked++)); break ;; + \ ?) break ;; + *) ((num_staged++)); break ;; + esac + done done <<< "$gitstatus" num_stashed=0 From 904b82bb5835e4257e178314affe9bddc28b8e0c Mon Sep 17 00:00:00 2001 From: DrVanScott Date: Sun, 17 Jul 2016 17:28:34 +0200 Subject: [PATCH 2/3] rewrite bash 4 ;;& operator (two step) --- gitstatus.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index e305990..e2b6bce 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -26,17 +26,26 @@ num_conflicts=0 num_untracked=0 while IFS='' read -r line || [[ -n "$line" ]]; do status=${line:0:2} - while true + while [[ -n $status ]] do case "$status" in +#two fixed character matches, loop finished \#\#) branch_line="${line/\.\.\./^}"; break ;; - ?M) ((num_changed++)); status=${status:0:1}"_" ;; - ?D) ((num_changed++)); status=${status:0:1}"_" ;; - U?) ((num_conflicts++)); break ;; \?\?) ((num_untracked++)); break ;; - \ ?) break ;; - *) ((num_staged++)); break ;; + U?) ((num_conflicts++)); break;; + ?U) ((num_conflicts++)); break;; + DD) ((num_conflicts++)); break;; + AA) ((num_conflicts++)); break;; +#two character matches, first loop + ?M) ((num_changed++)) ;; + ?D) ((num_changed++)) ;; + ?\ ) ;; +#single character matches, second loop + U) ((num_conflicts++)) ;; + \ ) ;; + *) ((num_staged++)) ;; esac + status=${status:0:-1} done done <<< "$gitstatus" From 5130f3b07d14fe9ed3f8e7cf254fdc91dfdf4103 Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 18 Jul 2016 10:49:29 +0200 Subject: [PATCH 3/3] Indentation same as other loop constructs --- gitstatus.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index e2b6bce..6d7db3c 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -26,21 +26,20 @@ num_conflicts=0 num_untracked=0 while IFS='' read -r line || [[ -n "$line" ]]; do status=${line:0:2} - while [[ -n $status ]] - do + while [[ -n $status ]]; do case "$status" in -#two fixed character matches, loop finished + #two fixed character matches, loop finished \#\#) branch_line="${line/\.\.\./^}"; break ;; \?\?) ((num_untracked++)); break ;; U?) ((num_conflicts++)); break;; ?U) ((num_conflicts++)); break;; DD) ((num_conflicts++)); break;; AA) ((num_conflicts++)); break;; -#two character matches, first loop + #two character matches, first loop ?M) ((num_changed++)) ;; ?D) ((num_changed++)) ;; ?\ ) ;; -#single character matches, second loop + #single character matches, second loop U) ((num_conflicts++)) ;; \ ) ;; *) ((num_staged++)) ;;