From 4a9fbbac351b3d67c5a9878a7cef8ad9958ad8a4 Mon Sep 17 00:00:00 2001 From: "dth@taiga.ai" Date: Sat, 18 Feb 2023 20:26:28 +0100 Subject: [PATCH] :sparkles: add script mzavoloka/gitls --- bashscripts/gitls | 23 +++++++++++++ bashscripts/gitls-cwd | 75 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100755 bashscripts/gitls create mode 100755 bashscripts/gitls-cwd diff --git a/bashscripts/gitls b/bashscripts/gitls new file mode 100755 index 0000000..dafd959 --- /dev/null +++ b/bashscripts/gitls @@ -0,0 +1,23 @@ +#!/bin/sh + +# https://github.com/mzavoloka/gitls + +dirs=${@:-$PWD} +gitls_script=$(realpath "${0}-cwd"); + +cd $PWD + +bold=$(tput bold) +reset=$(tput sgr0) + +for dir in $dirs +do + echo "$bold$dir:$reset" + if [ ! -e $dir ]; then + echo "$dir doesn't exist" + elif [ -d $dir ]; then + ( cd $dir && bash $gitls_script ) + else + echo "$dir is not a directory" + fi +done diff --git a/bashscripts/gitls-cwd b/bashscripts/gitls-cwd new file mode 100755 index 0000000..1f36f75 --- /dev/null +++ b/bashscripts/gitls-cwd @@ -0,0 +1,75 @@ +#!/bin/sh + +FILES=$(git ls-tree --name-only HEAD .) +MAXLEN=0 +IFS=$(printf "\n\b") +counter=0 +for f in $FILES; do + if [ ${#f} -gt $MAXLEN ]; then + MAXLEN=${#f}; + fi + counter=$((counter + 1)) +done +MAXLEN=$((MAXLEN+1)) # Consider slash at the end of dirname + +number_of_files=$counter +space_for_file_numbers=${#number_of_files} + +# colors definitions +blue=$(tput setaf 27) +normal=$(tput setaf 255) +black_bg=$(tput setab 233) +brown=$(tput setaf 237) +bold=$(tput bold) + +reset=$(tput sgr0) + +# format definitions +filename_format="$normal" +dirname_format="$reset$blue$bold" +file_numbers_format="$brown" + + +# # zebra definitions and format +# zebra_on_color=$(tput setab 237) +# zebra_off_color=$black_bg +# zebra=$() +# zebra_on=0 + +i=1 + +for f in $FILES; do + printf "$reset" + + # file numbers + printf "$file_numbers_format" + printf "%${space_for_file_numbers}d | " "$i" + + # # zebra calculation + # if [ $zebra_on -eq 1 ]; then + # zebra=$zebra_on_color + # zebra_on=0 + # else + # zebra=$zebra_off_color + # zebra_on=1 + # fi + + + str=$(git log -1 --pretty=format:"%<(23)%C(green)%cr%C(white) | %C(cyan)%h%C(white) | %<(15)%C(yellow)%cn%C(white) | %s" $f) + if [ -d "$f" ]; then + printf "$dirname_format" + else + printf "$filename_format" + fi + + if [ -d "$f" ]; then + f="$f/" + fi + + printf "%-${MAXLEN}s$reset" "$f" + + printf " -- %s\n" "$str" + i=$((i + 1)) +done + +printf "$(tput sgr 0)"