add script mzavoloka/gitls

This commit is contained in:
dth@taiga.ai 2023-02-18 20:26:28 +01:00
parent c58f1e13e5
commit 4a9fbbac35
2 changed files with 98 additions and 0 deletions

23
bashscripts/gitls Executable file
View file

@ -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

75
bashscripts/gitls-cwd Executable file
View file

@ -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)"