summaryrefslogtreecommitdiff
path: root/bin/common/gt-st
blob: 43443cd6175f0253d6606024316e9370c218916b (plain)
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
#!/bin/sh

# Print status of the repo locally

# path to repo
repo="$1"
[ "$1" ] || exit 1

repo_pretty="$(printf '%s' "$repo" | sed "s@$HOME@~@")"

if [ ! -d "$repo" ]; then
	printf '%s missing\n' "$repo_pretty"
	exit 1
fi

# replace line with status
status="$(git -C "$repo" status --porcelain 2>/dev/null |
	awk '{print $1}' |
	sort | uniq | tr -s '?' |
	tr -d '\n')"
remote="$(git -C "$repo" branch -v 2>/dev/null |
	sed '/^*/!d;s/ahead/↑/;s/behind/↓/;s/[^↓↑]*//g')"

if [ "$status" ] || [ "$remote" ]; then
	printf '%s: \033[0;31m%s %s\033[0m\n' "$repo_pretty" "$status" "$remote"
else
	printf '%s\n' "$repo_pretty"
fi