dot

packages and services management
Log | Files | Refs | README

commit 47a62fd2eb782751e270cfc1ec924143650e60de
parent 3fa04f5ed091cc25fe5cbd6bfb8306073790bfab
Author: josuah <mail@josuah.net>
Date:   Tue,  1 Nov 2016 16:44:35 -0400

Trying more compact yet readable shell syntax

Diffstat:
Mshell/.profile | 17+++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/shell/.profile b/shell/.profile @@ -55,9 +55,7 @@ git_status() { git rev-parse &>/dev/null || return 0 - local branch="$(git branch)" branch_line - printf %s "${branch#??}" - + local branch branch_line local behind=0 ahead=0 untracked=0 conflicts=0 changed=0 staged=0 while IFS='' read -r line @@ -74,7 +72,7 @@ git_status() ?U ) conflicts="$((conflicts + 1))"; break ;; DD ) conflicts="$((conflicts + 1))"; break ;; AA ) conflicts="$((conflicts + 1))"; break ;; - + # first loop: two character matches ?M ) changed="$((changed + 1))" ;; ?D ) changed="$((changed + 1))" ;; @@ -93,21 +91,20 @@ git_status() $(git status --porcelain -b) EOF + branch="${branch_line# ## }" branch="${branch%%...*}" branch_line="${branch_line%]}" - if [ -z "${branch_line##*ahead *}" ] + if [ -z "${branch_line##*ahead *}" ] then - ahead="${branch_line#*ahead }" - ahead="${ahead%, *}" + ahead="${branch_line#*ahead }" ahead="${ahead%, *}" fi if [ -z "${branch_line##*behind *}" ] then - behind="${branch_line#*behind }" - behind="${behind%, *}" + behind="${branch_line#*behind }" behind="${behind%, *}" fi - printf '\033[1m' + printf '\033[1m%s' "${branch#??}" if [ "$untracked$conflicts$changed$staged$ahead$behind" = '000000' ] then