From 518db6e648aaf646db4be3067a583bdcc37ee2a8 Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Sat, 4 Mar 2017 13:59:48 +0100 Subject: [PATCH] Columns in git-effort adopt to file length --- bin/git-effort | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/git-effort b/bin/git-effort index 4528ec9..8829451 100755 --- a/bin/git-effort +++ b/bin/git-effort @@ -5,6 +5,7 @@ above=0 # if the output won't be printed to tty, disable the color test -t 1 && to_tty=true color= +columns=45 # # print usage message @@ -104,7 +105,7 @@ effort() { len=${#path} dot="." f_dot="$path" - i=0 ; while test $i -lt $((45-$len)) ; do + i=0 ; while test $i -lt $(( $columns - $len )) ; do f_dot=$f_dot$dot i=$(($i+1)) done @@ -124,7 +125,7 @@ effort() { heading() { echo - printf " %-45s %-10s %s\n" 'path' 'commits' 'active days' + printf " %-${columns}s %-10s %s\n" 'path' 'commits' 'active days' echo } @@ -177,6 +178,10 @@ fi args_to_git_log="${args_to_git_log#\ \'\'}" export args_to_git_log +# set column width to match longest filename +columns=$(( $(git ls-files | awk '{ print length, $0 }' | sort -rn | head -1 | cut -f1 -d' ') + 5 )) +export columns + # [path ...] if test "${#paths}" -eq 0; then