summaryrefslogtreecommitdiff
path: root/bin/extra/supd
blob: 83a606b48f886f5bb84ecc7b5f25a49150e207a0 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh

usage() {
	>&2 cat <<-EOF
	usage: supd
	       supd <prefix> <dir>
		   stdout | supd <prefix>
	EOF
	exit 1
}

check ()
{
	for dir in $1
	do
		printf '%s: ' "$2/$dir" | sed "s#$HOME#~#" >&2
		cd "$2/$dir" || continue
		git pull > /dev/null 2>&1 &&
			printf 'Up to date.' ||
			printf 'Couldn'\''t update.'
		printf ' '
		printf '%s\n' "$(git status --short 2> /dev/null |
			awk 'NR==1 {print $1}')"
	done
}

if [ "$#" -eq 0 ]
then
	dirs="installdrier dotfiles password-store"
	prefix="$HOME/src"
elif [ ! -t 0 ]
then
	prefix="$1"
	dirs="$(cat)"
else
	prefix="$1"
	shift || usage
	dirs="$*"
	[ "$dirs" ] || usage
fi
check "$dirs" "$prefix"