90e16301634d75f2637acdf5765bac560db0da5f

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Merge pull request #4443 from apjanke/github-update

Update github plugin to work with current hub versions

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/github/README.md b/plugins/github/README.md
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..21b7367f736b72b3c6ac4c4a6429f85a83371fdb
  4--- /dev/null
  5+++ b/plugins/github/README.md
  6@@ -0,0 +1,46 @@
  7+#  github
  8+
  9+This plugin supports working with GitHub the command line. It provides a few things:
 10+
 11+* Sets up the `hub` wrapper and completions for the `git` command if you have `hub` installed.
 12+* Completion for the `github` Ruby gem.
 13+* Convenience functions for working with repos and URLs.
 14+
 15+###  Functions
 16+
 17+* `empty_gh` - Creates a new empty repo (with a `README.md`) and pushes it to GitHub
 18+* `new_gh` - Initializes an existing directory as a repo and pushes it to GitHub
 19+* `exist_gh` - Takes an existing repo and pushes it to GitHub
 20+* `git.io` - Shortens a URL using [git.io](http://git.io)
 21+
 22+
 23+##  Installation
 24+
 25+[Hub](http://github.com/github/hub) needs to be installed if you want to use it. On OS X with Homebrew, this can be done with `brew install hub`. The `hub` completion definition needs to be added to your `$FPATH` before initializing OMZ.
 26+
 27+The [`github` Ruby gem](http://github.com/defunkt/github-gem) needs to be installed if you want to use it.
 28+
 29+###  Configuration
 30+
 31+These settings affect `github`'s behavior.
 32+
 33+#### Environment variables
 34+
 35+* `$GITHUB_USER`
 36+* `$GITHUB_PASSWORD`
 37+
 38+#### Git configuration options
 39+
 40+* `github.user` - GitHub username for repo operations
 41+
 42+See `man hub` for more details.
 43+
 44+###  Homebrew installation note
 45+
 46diff --git a/plugins/github/_github b/plugins/github/_github
 47deleted file mode 100644
 48index 83e1713c774f5a6d898e9c3477cf5b11ee305084..0000000000000000000000000000000000000000
 49--- a/plugins/github/_github
 50+++ /dev/null
 51@@ -1,40 +0,0 @@
 52-#compdef github
 53-#autoload
 54-
 55-# in order to make this work, you will need to have the github gem installed
 56-# http://github.com/defunkt/github-gem
 57-
 58-# github zsh completion, based on homebrew completion
 59-
 60-local -a _1st_arguments
 61-_1st_arguments=(
 62-  'browse:Open this repo in a web browser'
 63-  'clone:Clone a repo'
 64-  'config:Automatically set configuration info, or pass args to specify'
 65-  'create-from-local:Create a new GitHub repository from the current local repository'
 66-  'create:Create a new empty GitHub repository'
 67-  'fetch:Fetch from a remote to a local branch'
 68-  'fetch_all:Fetch all refs from a user'
 69-  'fork:Forks a GitHub repository'
 70-  'home:Open this repos master branch in a web browser'
 71-  'ignore:Ignore a SHA from github network commits'
 72-  'info:Info about this project'
 73-  'issues:Project issues tools'
 74-  'network:Project network tools - sub-commands : web [user], list, fetch, commits'
 75-  'open:Open the given user/project in a web browser'
 76-  'pull-request:Generate the text for a pull request'
 77-  'pull:Pull from a remote'
 78-  'search:Search GitHub for the given repository name'
 79-  'track:Track another users repository'
 80-)
 81-
 82-local expl
 83-local -a pkgs installed_pkgs
 84-
 85-_arguments \
 86-  '*:: :->subcmds' && return 0
 87-
 88-if (( CURRENT == 1 )); then
 89-  _describe -t commands "github subcommand" _1st_arguments
 90-  return
 91-fi
 92diff --git a/plugins/github/github.plugin.zsh b/plugins/github/github.plugin.zsh
 93index bd69b1bd5ffaaaec95d4e46ae715cfc863adb8db..ca19901fd92df886c589e13f4cc2966feebec2c8 100644
 94--- a/plugins/github/github.plugin.zsh
 95+++ b/plugins/github/github.plugin.zsh
 96@@ -1,56 +1,25 @@
 97-# Setup hub function for git, if it is available; http://github.com/defunkt/hub
 98-if [ "$commands[(I)hub]" ] && [ "$commands[(I)ruby]" ]; then
 99-    # Autoload _git completion functions
100-    if declare -f _git > /dev/null; then
101-      _git
102-    fi
103-    
104-    if declare -f _git_commands > /dev/null; then
105-        _hub_commands=(
106-            'alias:show shell instructions for wrapping git'
107-            'pull-request:open a pull request on GitHub'
108-            'fork:fork origin repo on GitHub'
109-            'create:create new repo on GitHub for the current project'
110-            'browse:browse the project on GitHub'
111-            'compare:open GitHub compare view'
112-        )
113-        # Extend the '_git_commands' function with hub commands
114-        eval "$(declare -f _git_commands | sed -e 's/base_commands=(/base_commands=(${_hub_commands} /')"
115-    fi
116-    # eval `hub alias -s zsh`
117-    function git(){
118-        if ! (( $+_has_working_hub  )); then
119-            hub --version &> /dev/null
120-            _has_working_hub=$(($? == 0))
121-        fi
122-        if (( $_has_working_hub )) ; then
123-            hub "$@"
124-        else
125-            command git "$@"
126-        fi
127-    }
128+# Set up hub wrapper for git, if it is available; http://github.com/github/hub
129+if [ "$commands[(I)hub]" ]; then
130+  if hub --version &>/dev/null; then
131+    eval $(hub alias -s zsh)
132+  fi
133 fi
134 
135 # Functions #################################################################
136 
137-# https://github.com/dbb 
138+# Based on https://github.com/dbb/githome/blob/master/.config/zsh/functions
139 
140-
141-# empty_gh [NAME_OF_REPO]
142+# empty_gh <NAME_OF_REPO>
143 #
144 # Use this when creating a new repo from scratch.
145+# Creates a new repo with a blank README.md in it and pushes it up to GitHub.
146 empty_gh() { # [NAME_OF_REPO]
147-    repo=$1
148-    ghuser=$(  git config github.user )
149+  emulate -L zsh
150+  local repo=$1
151 
152-    mkdir "$repo"
153-    cd "$repo"
154-    git init
155-    touch README
156-    git add README
157-    git commit -m 'Initial commit.'
158-    git remote add origin git@github.com:${ghuser}/${repo}.git
159-    git push -u origin master
160+  mkdir "$repo"
161+  touch "$repo/README.md"
162+  new_gh "$repo"
163 }
164 
165 # new_gh [DIRECTORY]
166@@ -58,16 +27,25 @@ empty_gh() { # [NAME_OF_REPO]
167 # Use this when you have a directory that is not yet set up for git.
168 # This function will add all non-hidden files to git.
169 new_gh() { # [DIRECTORY]
170-    cd "$1"
171-    ghuser=$( git config github.user )
172+  emulate -L zsh
173+  local repo="$1"
174+  cd "$repo" \
175+    || return
176 
177-    git init
178-    # add all non-dot files
179-    print '.*'"\n"'*~' >> .gitignore
180-    git add ^.*
181-    git commit -m 'Initial commit.'
182-    git remote add origin git@github.com:${ghuser}/${repo}.git
183-    git push -u origin master
184+  git init \
185+    || return
186+  # add all non-dot files
187+  print '.*'"\n"'*~' >> .gitignore
188+  git add [^.]* \
189+    || return
190+  git add .gitignore \
191+    || return
192+  git commit -m 'Initial commit.' \
193+    || return
194+  hub create \
195+    || return