summaryrefslogtreecommitdiff
path: root/plugins/github/github.plugin.zsh
diff options
context:
space:
mode:
authorAndrew Janke <andrew@apjanke.net>2015-10-02 01:21:29 -0400
committerAndrew Janke <andrew@apjanke.net>2015-11-06 04:10:33 -0500
commit24492a2fdb6feed1b529459dbd97061460aa968f (patch)
tree33ea60bfa14e6c01c139b9817b77f26492ec7292 /plugins/github/github.plugin.zsh
parenta9c882094dedfdefb311db5967b974980cec49ec (diff)
downloadzsh-24492a2fdb6feed1b529459dbd97061460aa968f.tar.gz
zsh-24492a2fdb6feed1b529459dbd97061460aa968f.tar.bz2
zsh-24492a2fdb6feed1b529459dbd97061460aa968f.zip
Update github plugin to work with current hub versions
Removes old completion setup that breaks with current _git and _hub completions. Ruby is no longer required by hub; removes that test. Does not define new completions for hub; they are now defined by hub itself. Change the functions to use hub to create the repos on GitHub. Add error checking to the functions. Removes apparently-unused _github completion definition.
Diffstat (limited to 'plugins/github/github.plugin.zsh')
-rw-r--r--plugins/github/github.plugin.zsh101
1 files changed, 41 insertions, 60 deletions
diff --git a/plugins/github/github.plugin.zsh b/plugins/github/github.plugin.zsh
index bd69b1bd5..ca19901fd 100644
--- a/plugins/github/github.plugin.zsh
+++ b/plugins/github/github.plugin.zsh
@@ -1,56 +1,25 @@
-# Setup hub function for git, if it is available; http://github.com/defunkt/hub
-if [ "$commands[(I)hub]" ] && [ "$commands[(I)ruby]" ]; then
- # Autoload _git completion functions
- if declare -f _git > /dev/null; then
- _git
- fi
-
- if declare -f _git_commands > /dev/null; then
- _hub_commands=(
- 'alias:show shell instructions for wrapping git'
- 'pull-request:open a pull request on GitHub'
- 'fork:fork origin repo on GitHub'
- 'create:create new repo on GitHub for the current project'
- 'browse:browse the project on GitHub'
- 'compare:open GitHub compare view'
- )
- # Extend the '_git_commands' function with hub commands
- eval "$(declare -f _git_commands | sed -e 's/base_commands=(/base_commands=(${_hub_commands} /')"
- fi
- # eval `hub alias -s zsh`
- function git(){
- if ! (( $+_has_working_hub )); then
- hub --version &> /dev/null
- _has_working_hub=$(($? == 0))
- fi
- if (( $_has_working_hub )) ; then
- hub "$@"
- else
- command git "$@"
- fi
- }
+# 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
fi
# Functions #################################################################
-# https://github.com/dbb
+# Based on https://github.com/dbb/githome/blob/master/.config/zsh/functions
-
-# empty_gh [NAME_OF_REPO]
+# empty_gh <NAME_OF_REPO>
#
# Use this when creating a new repo from scratch.
+# Creates a new repo with a blank README.md in it and pushes it up to GitHub.
empty_gh() { # [NAME_OF_REPO]
- repo=$1
- ghuser=$( git config github.user )
+ emulate -L zsh
+ local repo=$1
- mkdir "$repo"
- cd "$repo"
- git init
- touch README
- git add README
- git commit -m 'Initial commit.'
- git remote add origin git@github.com:${ghuser}/${repo}.git
- git push -u origin master
+ mkdir "$repo"
+ touch "$repo/README.md"
+ new_gh "$repo"
}
# new_gh [DIRECTORY]
@@ -58,16 +27,25 @@ empty_gh() { # [NAME_OF_REPO]
# 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]
- cd "$1"
- ghuser=$( git config github.user )
+ emulate -L zsh
+ local repo="$1"
+ cd "$repo" \
+ || return
- git init
- # add all non-dot files
- print '.*'"\n"'*~' >> .gitignore
- git add ^.*
- git commit -m 'Initial commit.'
- git remote add origin git@github.com:${ghuser}/${repo}.git
- git push -u origin master
+ 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
}
# exist_gh [DIRECTORY]
@@ -75,13 +53,13 @@ new_gh() { # [DIRECTORY]
# Use this when you have a git repo that's ready to go and you want to add it
# to your GitHub.
exist_gh() { # [DIRECTORY]
- cd "$1"
- name=$( git config user.name )
- ghuser=$( git config github.user )
- repo=$1
+ emulate -L zsh
+ local repo=$1
+ cd "$repo"
- git remote add origin git@github.com:${ghuser}/${repo}.git
- git push -u origin master
+ hub create \
+ || return
+ git push -u origin master
}
# git.io "GitHub URL"
@@ -91,7 +69,10 @@ exist_gh() { # [DIRECTORY]
# source: https://github.com/nvogel/dotzsh
# documentation: https://github.com/blog/985-git-io-github-url-shortener
#
-git.io() {curl -i -s http://git.io -F "url=$1" | grep "Location" | cut -f 2 -d " "}
+git.io() {
+ emulate -L zsh
+ curl -i -s http://git.io -F "url=$1" | grep "Location" | cut -f 2 -d " "
+}
# End Functions #############################################################