diff options
| author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-10-23 12:27:52 +0200 | 
|---|---|---|
| committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-10-23 12:27:52 +0200 | 
| commit | bcd58fb05c588a4637a7f983f79b66b4d86d4d0d (patch) | |
| tree | 45d8d804fd469d6f70e0aa57d41e1e8267b0493a /bin/extra/supd | |
| parent | 6c3c0fdcb47423a0e15e91afd6fa32268be120b9 (diff) | |
refactored, removed prefix option
Diffstat (limited to 'bin/extra/supd')
| -rwxr-xr-x | bin/extra/supd | 68 | 
1 files changed, 30 insertions, 38 deletions
diff --git a/bin/extra/supd b/bin/extra/supd index 4975b94..c8a36bc 100755 --- a/bin/extra/supd +++ b/bin/extra/supd @@ -1,44 +1,36 @@  #!/bin/sh -usage() { -	>&2 cat <<-EOF -	usage: supd -	       supd <prefix> <dir> -		   stdout | supd <prefix> -	EOF -	exit 1 -} +# To add? +# 	- possibility of changing verb pull/fetch/push +# 	- adding prefix -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 %s\n' "$(git status --short 2> /dev/null | -			awk 'NR==1 {print $1}')" "$(git branch -v 2>/dev/null | -			grep '^\*' | cut -f2 -d'[' | cut -f1 -d' ' | -			sed 's/ahead/↑/;s/behind/↓/;s/\*//')" +ls() { find . -mindepth 1 -maxdepth 1 -type d -not -name ".*" -printf '%f\n';  } -	done -} - -if [ "$#" -eq 0 ] -then -	dirs="installdrier dotfiles password-store" -	prefix="$HOME/src" -elif [ ! -t 0 ] +if [ "$1" = '-h' ]  then -	prefix="$1" -	dirs="$(cat)" -else -	prefix="$1" -	shift || usage -	dirs="$*" -	[ "$dirs" ] || usage +	>&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 -check "$dirs" "$prefix" + +[ ! -t 0 ] && dirs="$(cat)" || dirs="$(ls)" + +for dir in $dirs +do +	printf '%s: ' "$dir" | >&2 sed "s#$HOME#~#" +	( +	cd "$dir" || exit +	git pull > /dev/null 2>&1 && +		printf 'Up to date.' || +		printf 'Couldn'\''t update.' +	# Show remote state +	printf ' %s %s\n' "$(git status --short 2> /dev/null | +		awk 'NR==1 {print $1}')" "$(git branch -v 2>/dev/null | +		grep '^\*' | cut -f2 -d'[' | cut -f1 -d' ' | +		sed 's/ahead/↑/;s/behind/↓/;s/\*//')" +	) +done  | 
