github.plugin.zsh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Set up hub wrapper for git, if it is available; http://github.com/github/hub
  2. if [ "$commands[(I)hub]" ]; then
  3. if hub --version &>/dev/null; then
  4. eval $(hub alias -s zsh)
  5. fi
  6. fi
  7. # Functions #################################################################
  8. # Based on https://github.com/dbb/githome/blob/master/.config/zsh/functions
  9. # empty_gh <NAME_OF_REPO>
  10. #
  11. # Use this when creating a new repo from scratch.
  12. # Creates a new repo with a blank README.md in it and pushes it up to GitHub.
  13. empty_gh() { # [NAME_OF_REPO]
  14. emulate -L zsh
  15. local repo=$1
  16. mkdir "$repo"
  17. touch "$repo/README.md"
  18. new_gh "$repo"
  19. }
  20. # new_gh [DIRECTORY]
  21. #
  22. # Use this when you have a directory that is not yet set up for git.
  23. # This function will add all non-hidden files to git.
  24. new_gh() { # [DIRECTORY]
  25. emulate -L zsh
  26. local repo="$1"
  27. cd "$repo" \
  28. || return
  29. git init \
  30. || return
  31. # add all non-dot files
  32. print '.*'"\n"'*~' >> .gitignore
  33. git add [^.]* \
  34. || return
  35. git add .gitignore \
  36. || return
  37. git commit -m 'Initial commit.' \
  38. || return
  39. hub create \
  40. || return
  41. git push -u origin master \
  42. || return
  43. }
  44. # exist_gh [DIRECTORY]
  45. #
  46. # Use this when you have a git repo that's ready to go and you want to add it
  47. # to your GitHub.
  48. exist_gh() { # [DIRECTORY]
  49. emulate -L zsh
  50. local repo=$1
  51. cd "$repo"
  52. hub create \
  53. || return
  54. git push -u origin master
  55. }
  56. # git.io "GitHub URL"
  57. #
  58. # Shorten GitHub url, example:
  59. # https://github.com/nvogel/dotzsh > http://git.io/8nU25w
  60. # source: https://github.com/nvogel/dotzsh
  61. # documentation: https://github.com/blog/985-git-io-github-url-shortener
  62. #
  63. git.io() {
  64. emulate -L zsh
  65. curl -i -s https://git.io -F "url=$1" | grep "Location" | cut -f 2 -d " "
  66. }
  67. # End Functions #############################################################