diff options
Diffstat (limited to 'bin')
-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 |