github.plugin.zsh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. # eval `hub alias -s zsh`
  4. function git(){
  5. if ! (( $+_has_working_hub )); then
  6. hub --version &> /dev/null
  7. _has_working_hub=$(($? == 0))
  8. fi
  9. if (( $_has_working_hub )) ; then
  10. hub "$@"
  11. else
  12. command git "$@"
  13. fi
  14. }
  15. fi
  16. # Functions #################################################################
  17. # https://github.com/dbb
  18. # empty_gh [NAME_OF_REPO]
  19. #
  20. # Use this when creating a new repo from scratch.
  21. empty_gh() { # [NAME_OF_REPO]
  22. repo = $1
  23. ghuser=$( git config github.user )
  24. mkdir "$repo"
  25. cd "$repo"
  26. git init
  27. touch README
  28. git add README
  29. git commit -m 'Initial commit.'
  30. git remote add origin git@github.com:${ghuser}/${repo}.git
  31. git push -u origin master
  32. }
  33. # new_gh [DIRECTORY]
  34. #
  35. # Use this when you have a directory that is not yet set up for git.
  36. # This function will add all non-hidden files to git.
  37. new_gh() { # [DIRECTORY]
  38. cd "$1"
  39. ghuser=$( git config github.user )
  40. git init
  41. # add all non-dot files
  42. print '.*'"\n"'*~' >> .gitignore
  43. git add ^.*
  44. git commit -m 'Initial commit.'
  45. git remote add origin git@github.com:${ghuser}/${repo}.git
  46. git push -u origin master
  47. }
  48. # exist_gh [DIRECTORY]
  49. #
  50. # Use this when you have a git repo that's ready to go and you want to add it
  51. # to your GitHub.
  52. exist_gh() { # [DIRECTORY]
  53. cd "$1"
  54. name=$( git config user.name )
  55. ghuser=$( git config github.user )
  56. repo=$1
  57. git remote add origin git@github.com:${ghuser}/${repo}.git
  58. git push -u origin master
  59. }
  60. # End Functions #############################################################