summaryrefslogtreecommitdiff
path: root/bin/extra/supd
blob: 48638bdee68942e96580118dc3d41b23f6d2f85a (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
#!/bin/sh

ls() { find . -mindepth 1 -maxdepth 1 -type d -not -name ".*" -printf '%f\n';  }

if [ "$1" = '-h' ]
then
	>&2 cat <<-EOF
	usage:
	    supd                              Update dirs in current dir
	    ls ~/projects | supd              Update dirs read from stdin
	    supd -h                           Show help
	EOF
	exit
fi

[ ! -t 0 ] && dirs="$(cat)" || dirs="$(ls)"

for dir in $dirs
do
	printf '%s:' "$dir" | >&2 sed "s#$HOME#~#"
	(
	cd "$dir" || return
    git "${1:-fetch}" > /dev/null 2>&1 &&
        printf ' o' ||
        printf ' x'
    # Show remote state
    printf '%s %s\n' "$(git status --short 2> /dev/null |
        awk 'NR==1 {print $1}')" "$(git branch -v 2>/dev/null |
        awk -F '[][]' '/^\*/ {print $2}')" |
        sed 's/ahead/↑ /;s/behind/↓ /;s/[^↓↑]*/ /g'
	)
done