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 | [email protected]:foo/foobar.git foo | [email protected]:bar/foobar.git bar | [email protected]: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 ([email protected]:foo/foobar.git)
# > bar ([email protected]:bar/foobar.git)
# > baz ([email protected]:baz/foobar.git)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment