-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathgstt
executable file
·86 lines (82 loc) · 2.24 KB
/
gstt
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
81
82
83
84
85
86
#!/usr/bin/env zsh
#
# Display short `git status` sorted by last modification.
#
# This is useful to get an overview about which files have been touched
# lately.
#
# Given the `-a` option it will call `git add -p` on all files (in sorted order).
while [[ $1 == -* ]] ; do
case $1 in
(-a) call_cmd=(git add -p)
call_cmd_for_unknown=(git add)
call_cmd_for_rm=(git rm) ;;
(-c) call_cmd=(git checkout -p) ;;
(--) shift ; break ;;
(-h)
printf 'List files according to `git status`, sorted by last modification date.'
printf 'Usage: gstt [-a|-c]\n'
printf ' -a call `git add (-p)` / `git rm` on files.\n'
printf ' -c call `git checkout -p` on files.\n'
return 0
;;
(*) printf "Warning: unkown option: '%s'. Use -- to pass options to git.\n" "$1" ; return 1 ;;
esac
shift
done
gstt() {
for line in ${(f)"$(git status --short "$@")"}; do
st=$line[1,2] ; fname=$line[4,-1]
# echo -E $line | read -r st fname
if [ -e $fname ] || [ -h $fname ]; then
# TODO: quoting
# stat: invalid option -- 'v'
# Try 'stat --help' for more information.
# ?? -v
echo "${$(stat -c %y -- ${(q-)fname})[1,19]} $st ${(q-)fname}"
else
# unknown/deleted: use git-log for timestamp.
echo "${$(git log -1 --pretty=format:%cd --date=iso -- ${(q-)fname})[1,19]} $st ${(q-)fname}"
fi
done | sort -r
}
if ((#call_cmd)); then
for i in ${(f)"$(gstt "$@")"}; do
wd_status=$(echo $i | cut -b22)
if [[ $wd_status == ' ' ]]; then
# skip: already in index (would result in "No changes." for "git add")
continue
fi
fname=$(echo $i | cut -b24-)
echo "--- $i ---"
if [[ $wd_status != "D" ]]; then
ls -ld $fname
fi
if [[ $wd_status == '?' ]] && [[ ${#call_cmd_for_unknown} -gt 0 ]]; then
if [[ -d $fname ]]; then
ls -l $fname
read -q "yn?Add the dir? (y/n) "
else
read -q "yn?Add the file? (y/n) "
fi
echo
if [[ $yn == 'y' ]]; then
$call_cmd_for_unknown $fname
fi
elif [[ $wd_status == 'D' ]] && [[ ${#call_cmd_for_rm} -gt 0 ]]; then
if [[ -d $fname ]]; then
read -q "yn?Remove the dir? (y/n) "
else
read -q "yn?Remove the file? (y/n) "
fi
echo
if [[ $yn == 'y' ]]; then
$call_cmd_for_rm $fname
fi
else
$call_cmd $fname
fi
done
else
gstt "$@"
fi