github.plugin.zsh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Setup hub function for git, if it is available; http://github.com/defunkt/hub
  2. if [ "$commands[(I)hub]" ] && [ "$commands[(I)ruby]" ]; then
  3. # Autoload _git completion functions
  4. if declare -f _git > /dev/null; then
  5. _git
  6. fi
  7. if declare -f _git_commands > /dev/null; then
  8. _hub_commands=(
  9. 'alias:show shell instructions for wrapping git'
  10. 'pull-request:open a pull request on GitHub'
  11. 'fork:fork origin repo on GitHub'
  12. 'create:create new repo on GitHub for the current project'
  13. 'browse:browse the project on GitHub'
  14. 'compare:open GitHub compare view'
  15. )
  16. # Extend the '_git_commands' function with hub commands
  17. eval "$(declare -f _git_commands | sed -e 's/base_commands=(/base_commands=(${_hub_commands} /')"
  18. fi
  19. # eval `hub alias -s zsh`
  20. function git(){
  21. if ! (( $+_has_working_hub )); then
  22. hub --version &> /dev/null
  23. _has_working_hub=$(($? == 0))
  24. fi
  25. if (( $_has_working_hub )) ; then
  26. hub "$@"
  27. else
  28. command git "$@"
  29. fi
  30. }
  31. fi
  32. # Functions #################################################################
  33. # https://github.com/dbb
  34. # empty_gh [NAME_OF_REPO]
  35. #
  36. # Use this when creating a new repo from scratch.
  37. empty_gh() { # [NAME_OF_REPO]
  38. repo = $1
  39. ghuser=$( git config github.user )
  40. mkdir "$repo"
  41. cd "$repo"
  42. git init
  43. touch README
  44. git add README
  45. git commit -m 'Initial commit.'
  46. git remote add origin git@github.com:${ghuser}/${repo}.git
  47. git push -u origin master
  48. }
  49. # new_gh [DIRECTORY]
  50. #
  51. # Use this when you have a directory that is not yet set up for git.
  52. # This function will add all non-hidden files to git.
  53. new_gh() { # [DIRECTORY]
  54. cd "$1"
  55. ghuser=$( git config github.user )
  56. git init
  57. # add all non-dot files
  58. print '.*'"\n"'*~' >> .gitignore
  59. git add ^.*
  60. git commit -m 'Initial commit.'
  61. git remote add origin git@github.com:${ghuser}/${repo}.git
  62. git push -u origin master
  63. }
  64. # exist_gh [DIRECTORY]
  65. #
  66. # Use this when you have a git repo that's ready to go and you want to add it
  67. # to your GitHub.
  68. exist_gh() { # [DIRECTORY]
  69. cd "$1"
  70. name=$( git config user.name )
  71. ghuser=$( git config github.user )
  72. repo=$1
  73. git remote add origin git@github.com:${ghuser}/${repo}.git
  74. git push -u origin master
  75. }
  76. # End Functions #############################################################