Advertisement
Guest User

Untitled

a guest
Jun 16th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. FIELD_SEP="|"
  4. 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 |"
  5.  
  6. # cut out the directory first
  7. DIR=${ROW%%${FIELD_SEP}*}
  8. TRIMMED_DIR="$(echo -e "${DIR}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
  9. ROW="${ROW#*${FIELD_SEP}}"
  10. echo "> dir: $DIR"
  11.  
  12. # loop through all defined repos
  13. echo "> remotes:"
  14. while [ "$ROW" ] ;do
  15. REMOTE=${ROW%%${FIELD_SEP}*}
  16. TRIMMED_REMOTE=($(echo -e "${REMOTE}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'))
  17. echo "> ${TRIMMED_REMOTE[1]} (${TRIMMED_REMOTE[0]})"
  18. [ "$ROW" = "$REMOTE" ] && ROW='' || ROW="${ROW#*${FIELD_SEP}}"
  19. done
  20.  
  21. # output:
  22. #
  23. # > dir: src/foo\ bar
  24. # > remotes:
  25. # > foo (git@github.com:foo/foobar.git)
  26. # > bar (git@github.com:bar/foobar.git)
  27. # > baz (git@github.com:baz/foobar.git)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement