-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitmod
More file actions
executable file
·42 lines (32 loc) · 1010 Bytes
/
gitmod
File metadata and controls
executable file
·42 lines (32 loc) · 1010 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
35
36
37
38
39
40
41
42
#!/bin/bash
cmd=$(basename $0)
usageStr="$cmd helps view or revert uncommitted file changes in git repo.
Usage: $cmd [-h] [-d path]
-h - Optional; Displays this help message and exits
-d path - Optional; Filters modified files/folders using given path
NOTE: If user just presses <ENTER>, $cmd goes to next modified file
"
[ "$1" == "-h" ] && printf "${usageStr}" && exit 0
[ "$1" == "-d" ] && dir="$2" && dir="${dir#./}" || dir=""
_gitmod_act()
{
local f=${@}
while true; do
read -p "*********** ${f} o(open diff & file) u(undo) x(exit): " op
case $op in
o) vim -R <(git diff ${f}) -O ${f} -c "wincmd l | set noreadonly" ;;
u) git checkout "${f}" ; break ;;
x) rm -rf ${modlist} && exit 0 ;;
*) break ;;
esac
done
}
modlist=/tmp/git-mod-file.lst
git diff --name-only > ${modlist}
while read -r line <&3; do
file="$(echo ${line} | awk '{print $1}')"
[ -n "${dir}" ] && [[ "${file}" != *${dir}* ]] && continue
_gitmod_act "$file"
done 3<${modlist}
rm -rf ${modlist}
exit 0