-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgit-parent
executable file
·32 lines (27 loc) · 895 Bytes
/
git-parent
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
#!/bin/bash
# Finds the direct parent of the current branch in git.
usage() {
(
echo "usage: ${0##*/} [-h|--help] [-r]"
echo "Finds the direct parent of the current branch in git."
echo
echo "options:"
(
echo " -h, --help: show usage help"
) | column -ts:
) >&2
exit 1
}
if echo "$*" | grep -Eq -- '--help\b|-h\b'; then
usage
fi
while getopts "r" opt; do
case "$opt" in
*) usage ;;
esac
done
shift $((OPTIND - 1))
vbc=$(git rev-parse --abbrev-ref HEAD)
vbc_col=$(($(git show-branch | grep '^[^\[]*\*' | head -1 | cut -d'*' -f1 | wc -c) - 1))
swimming_lane_start_row=$(($(git show-branch | grep -n "^[\\-]*$" | cut -d: -f1) + 1))
git show-branch | tail -n +$swimming_lane_start_row | grep -v "^[^\\[]*\\[$vbc" | grep "^.\\{$vbc_col\\}[^ ]" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//'