-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-reopen
executable file
·48 lines (46 loc) · 1.04 KB
/
git-reopen
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
#!/bin/bash
#PURPOSE: re-open recently edited files
cdup="$(git rev-parse --show-cdup)"
HEAD="$1"
status=
oldname=
{
if [ -n "$HEAD" ]; then
if echo "$HEAD" | grep -q '\.\.'; then
git log -z --pretty=format: --name-status "$HEAD"
else
git log -z --pretty=format: -1 --name-status "$HEAD"
fi
elif { git diff --name-status; git diff --cached --name-status; } | grep -q '^[AMR]'; then
git diff -z --cached --name-status
git diff -z --name-status
else
git log -z --pretty=format: -1 --name-status
fi
} | while read -d $'\0' part; do
if [ -z "$status" ]; then
status="$part"
continue
fi
if [ -z "$oldname" ]; then
if [ "$status" = "${status#R}" ]; then
#status does not begin with "R", so there is only one name
if [ \
"$status" != "${status#A}" -o \
"$status" != "${status#M}" \
]; then
#status begins with A or M
echo "$cdup$part"
fi
status=
continue
fi
oldname="$part"
continue
fi
echo "$cdup$part"
status=
oldname=
done | sort -u | while read path; do
"${EDITOR-gvim}" "$path"
done