sh.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. # Script to open a browser to current branch
  3. # Repo formats:
  4. # ssh git@github.com:richo/gh_pr.git
  5. # http https://richoH@github.com/richo/gh_pr.git
  6. # git git://github.com/richo/gh_pr.git
  7. username=`git config --get github.user`
  8. get_repo() {
  9. git remote -v | grep ${@:-$username} | while read remote; do
  10. if repo=`echo $remote | grep -E -o "git@github.com:[^ ]*"`; then
  11. echo $repo | sed -e "s/^git@github\.com://" -e "s/\.git$//"
  12. exit 1
  13. fi
  14. if repo=`echo $remote | grep -E -o "https?://([^@]*@)?github.com/[^ ]*\.git"`; then
  15. echo $repo | sed -e "s|^https?://||" -e "s/^.*github\.com\///" -e "s/\.git$//"
  16. exit 1
  17. fi
  18. if repo=`echo $remote | grep -E -o "git://github.com/[^ ]*\.git"`; then
  19. echo $repo | sed -e "s|^git://github.com/||" -e "s/\.git$//"
  20. exit 1
  21. fi
  22. done
  23. if [ $? -eq 0 ]; then
  24. echo "Couldn't find a valid remote" >&2
  25. exit 1
  26. fi
  27. }
  28. echo ${#x[@]}
  29. if repo=`get_repo $@`; then
  30. branch=`git symbolic-ref HEAD 2>/dev/null`
  31. echo "http://github.com/$repo/pull/new/${branch##refs/heads/}"
  32. else
  33. exit 1
  34. fi