github.plugin.zsh 1.73 KB
Newer Older
Janosch Schwalm's avatar
Janosch Schwalm committed
1
# Set up hub wrapper for git, if it is available; https://github.com/github/hub
2
3
if (( $+commands[hub] )); then
  alias git=hub
4
fi
5
6
7

# Functions #################################################################

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
16
  emulate -L zsh
  local repo=$1
17

18
19
20
  mkdir "$repo"
  touch "$repo/README.md"
  new_gh "$repo"
21
22
23
24
25
26
27
}

# new_gh [DIRECTORY]
#
# Use this when you have a directory that is not yet set up for git.
# This function will add all non-hidden files to git.
new_gh() { # [DIRECTORY]
28
29
30
31
  emulate -L zsh
  local repo="$1"
  cd "$repo" \
    || return
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
  git init \
    || return
  # add all non-dot files
  print '.*'"\n"'*~' >> .gitignore
  git add [^.]* \
    || return
  git add .gitignore \
    || return
  git commit -m 'Initial commit.' \
    || return
  hub create \
    || return
  git push -u origin master \
    || return
47
48
}

49
50
51
52
# exist_gh [DIRECTORY]
#
# Use this when you have a git repo that's ready to go and you want to add it
# to your GitHub.
53
exist_gh() { # [DIRECTORY]
54
55
56
  emulate -L zsh
  local repo=$1
  cd "$repo"
57

58
59
60
  hub create \
    || return
  git push -u origin master
61
62
}

Samvel Khalatyan's avatar
Samvel Khalatyan committed
63
64
65
# git.io "GitHub URL"
#
# Shorten GitHub url, example:
Janosch Schwalm's avatar
Janosch Schwalm committed
66
#   https://github.com/nvogel/dotzsh    >   https://git.io/8nU25w
Samvel Khalatyan's avatar
Samvel Khalatyan committed
67
68
69
# source: https://github.com/nvogel/dotzsh
# documentation: https://github.com/blog/985-git-io-github-url-shortener
#
70
71
git.io() {
  emulate -L zsh
Sharat M R's avatar
Sharat M R committed
72
  curl -i -s https://git.io -F "url=$1" | grep "Location" | cut -f 2 -d " "
73
}
Samvel Khalatyan's avatar
Samvel Khalatyan committed
74

75
76
# End Functions #############################################################