github.plugin.zsh 1.9 KB

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