-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-edit
executable file
·32 lines (30 loc) · 906 Bytes
/
git-edit
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
#!/usr/bin/env bash
# Usage: git-edit [conflicted|staged|edited|commited]
# If no option is passed, edited is the default
main() {
local action="$1"
case $action in
conflict | conflicts | conflicted)
read -r -d ' ' -a files < <(git diff --name-only --diff-filter=U)
;;
commited)
read -r -d ' ' -a files < <(git diff HEAD^ --name-only --diff-filter=ACMR)
;;
staged)
read -r -d ' ' -a files < <(git diff --staged --name-only --diff-filter=ACMR)
;;
edited)
read -r -d ' ' -a files < <(git diff HEAD --name-only --diff-filter=ACMR)
;;
*)
read -r -d ' ' -a files < <(git diff HEAD --name-only --diff-filter=ACMR)
;;
esac
if [[ -n ${files[*]} ]]; then
echo "Opening ${#files[*]} files"
$EDITOR "${files[@]}"
else
echo "No files match '${action}'"
fi
}
main "$@"