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