-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgitls-cwd
More file actions
75 lines (57 loc) · 1.38 KB
/
gitls-cwd
File metadata and controls
75 lines (57 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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 --color --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 -- %s\n" "$f" "$str"
i=$((i + 1))
done
printf "$(tput sgr 0)"