-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-brief
More file actions
executable file
·80 lines (68 loc) · 1.69 KB
/
Copy pathgit-brief
File metadata and controls
executable file
·80 lines (68 loc) · 1.69 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
76
77
78
79
80
#!/bin/zsh
# vim:ft=zsh
#
# git-st - Enhanced git status with numbered file shortcuts
#
# Processes 'git status --porcelain', and exports numbered env variables that contain
# the path of each affected file. Integrates with scmpuff if available.
#
# see https://github.com/mroth/scmpuff
#==================================================
#
show_help() {
printf -- "
git-st - Enhanced git status command
Usage: git st [OPTIONS]
Options:
-h, Show this help message
Description:
Enhanced git status. One-line status for each file with lines added and removed.
The Original version by https://www.reddit.com/user/ex1c
Examples:
git st # Show status
"
exit 0
}
check_git_status() {
local IFS
local git_status
git_status=("${(@f)$(git -c color.status=always status -sb)}")
if [[ $? -ne 0 ]]; then
return 1
fi
local diff
diff=("${(@f)$(git diff --color --stat HEAD 2>/dev/null | sed '$d; s/^ //' | cut -d '|' -f 2)}")
local len=-1
for ((i=1; i<${#git_status[@]}; i++)); do
if (( ${#git_status[i]} > len )); then
len=${#git_status[i]}
fi
done
(( len *= -1 ))
for ((i=0; i<${#git_status[@]}; i++)); do
local currStatus="${git_status[i]}"
if (( i == 0 )); then
echo "${git_status[0]}" | cut -d ' ' -f 2-
else
local currDiff=""
if [[ -n "${diff[i-1]}" ]]; then
currDiff="|${diff[i-1]}"
fi
printf "%*s %s\n" $len "${currStatus}" "${currDiff}"
fi
done
if (( ${#git_status[@]} - 1 == 0 )); then
git -c color.status=always status -b
fi
}
main() {
case "$1" in
-h|--help)
show_help
;;
*)
check_git_status "$@"
;;
esac
}
main "$@"