Skip to content

Instantly share code, notes, and snippets.

@dsager
Last active August 29, 2015 14:21
Show Gist options
  • Save dsager/00cad170e0e752a3ca27 to your computer and use it in GitHub Desktop.
Save dsager/00cad170e0e752a3ca27 to your computer and use it in GitHub Desktop.
small script to parse a string containing a git repository definition with multiple remotes.
#!/usr/bin/env bash
FIELD_SEP="|"
ROW="src/foo\ bar | git@github.com:foo/foobar.git foo | git@github.com:bar/foobar.git bar | git@github.com:baz/foobar.git baz |"
# cut out the directory first
DIR=${ROW%%${FIELD_SEP}*}
TRIMMED_DIR="$(echo -e "${DIR}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
ROW="${ROW#*${FIELD_SEP}}"
echo "> dir: $DIR"
# loop through all defined repos
echo "> remotes:"
while [ "$ROW" ] ;do
REMOTE=${ROW%%${FIELD_SEP}*}
TRIMMED_REMOTE=($(echo -e "${REMOTE}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'))
echo "> ${TRIMMED_REMOTE[1]} (${TRIMMED_REMOTE[0]})"
[ "$ROW" = "$REMOTE" ] && ROW='' || ROW="${ROW#*${FIELD_SEP}}"
done
# output:
#
# > dir: src/foo\ bar
# > remotes:
# > foo (git@github.com:foo/foobar.git)
# > bar (git@github.com:bar/foobar.git)
# > baz (git@github.com:baz/foobar.git)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment