github.plugin.zsh 1.78 KB
Newer Older
1
2
3
4
5
# Set up hub wrapper for git, if it is available; http://github.com/github/hub
if [ "$commands[(I)hub]" ]; then
  if hub --version &>/dev/null; then
    eval $(hub alias -s zsh)
  fi
6
fi
7
8
9

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

10
# Based on https://github.com/dbb/githome/blob/master/.config/zsh/functions
11

12
# empty_gh <NAME_OF_REPO>
13
14
#
# Use this when creating a new repo from scratch.
15
# Creates a new repo with a blank README.md in it and pushes it up to GitHub.
16
empty_gh() { # [NAME_OF_REPO]
17
18
  emulate -L zsh
  local repo=$1
19

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

# 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]
30
31
32
33
  emulate -L zsh
  local repo="$1"
  cd "$repo" \
    || return
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
  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
49
50
}

51
52
53
54
# 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.
55
exist_gh() { # [DIRECTORY]
56
57
58
  emulate -L zsh
  local repo=$1
  cd "$repo"
59

60
61
62
  hub create \
    || return
  git push -u origin master
63
64
}

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

77
78
# End Functions #############################################################