-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvihead
More file actions
executable file
·34 lines (31 loc) · 742 Bytes
/
vihead
File metadata and controls
executable file
·34 lines (31 loc) · 742 Bytes
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
#!/bin/sh
## In a git tree, list files from the last commit (HEAD), offer a selection and
## open in vim with the diff against HEAD^ (i.e. the last changes to the file).
#
# requires: fugitive-vim plugin
diff="$(git show)"
fn=
if [ $? = 0 ]; then
select fn in $(git show HEAD | lsdiff --strip 1); do
break;
done
# can be run anywhere in the directory tree, diff prints path relative
# to the toplevel
fn=$(realpath -e --relative-to=`pwd` ./`git rev-parse --show-cdup`/"$fn")
echo "FN: $fn"
if ! [ -f "$fn" ]; then
echo "File not found"
exit
fi
else
echo "not in git?"
fi
if [ -z "$fn" ]; then
if [ -z "$1" ]; then
echo "gimmea file"
exit 1
fi
vi -c ":Gvdiffsplit HEAD^" "$@"
else
vi -c ":Gvdiffsplit HEAD^" "$fn"
fi