mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-14 01:40:09 +00:00
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.
This commit is contained in:
parent
a9c882094d
commit
24492a2fdb
3 changed files with 87 additions and 100 deletions
46
plugins/github/README.md
Normal file
46
plugins/github/README.md
Normal file
|
@ -0,0 +1,46 @@
|
|||
# github
|
||||
|
||||
This plugin supports working with GitHub the command line. It provides a few things:
|
||||
|
||||
* Sets up the `hub` wrapper and completions for the `git` command if you have `hub` installed.
|
||||
* Completion for the `github` Ruby gem.
|
||||
* Convenience functions for working with repos and URLs.
|
||||
|
||||
### Functions
|
||||
|
||||
* `empty_gh` - Creates a new empty repo (with a `README.md`) and pushes it to GitHub
|
||||
* `new_gh` - Initializes an existing directory as a repo and pushes it to GitHub
|
||||
* `exist_gh` - Takes an existing repo and pushes it to GitHub
|
||||
* `git.io` - Shortens a URL using [git.io](http://git.io)
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
[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.
|
||||
|
||||
The [`github` Ruby gem](http://github.com/defunkt/github-gem) needs to be installed if you want to use it.
|
||||
|
||||
### Configuration
|
||||
|
||||
These settings affect `github`'s behavior.
|
||||
|
||||
#### Environment variables
|
||||
|
||||
* `$GITHUB_USER`
|
||||
* `$GITHUB_PASSWORD`
|
||||
|
||||
#### Git configuration options
|
||||
|
||||
* `github.user` - GitHub username for repo operations
|
||||
|
||||
See `man hub` for more details.
|
||||
|
||||
### Homebrew installation note
|
||||
|
||||
If you have installed `hub` using Homebrew, its completions may not be on your `$FPATH` if you are using the system `zsh`. Homebrew installs `zsh` completion definitions to `/usr/local/share/zsh/site-functions`, which on `$FPATH` for the Homebrew-installed `zsh`, but not for the system `zsh`. If you want it to work with the system `zsh`, add this to your `~/.zshrc` before it sources `oh-my-zsh.sh`.
|
||||
|
||||
```zsh
|
||||
if (( ! ${fpath[(I)/usr/local/share/zsh/site-functions]} )); then
|
||||
FPATH=/usr/local/share/zsh/site-functions:$FPATH
|
||||
fi
|
||||
```
|
|
@ -1,40 +0,0 @@
|
|||
#compdef github
|
||||
#autoload
|
||||
|
||||
# in order to make this work, you will need to have the github gem installed
|
||||
# http://github.com/defunkt/github-gem
|
||||
|
||||
# github zsh completion, based on homebrew completion
|
||||
|
||||
local -a _1st_arguments
|
||||
_1st_arguments=(
|
||||
'browse:Open this repo in a web browser'
|
||||
'clone:Clone a repo'
|
||||
'config:Automatically set configuration info, or pass args to specify'
|
||||
'create-from-local:Create a new GitHub repository from the current local repository'
|
||||
'create:Create a new empty GitHub repository'
|
||||
'fetch:Fetch from a remote to a local branch'
|
||||
'fetch_all:Fetch all refs from a user'
|
||||
'fork:Forks a GitHub repository'
|
||||
'home:Open this repos master branch in a web browser'
|
||||
'ignore:Ignore a SHA from github network commits'
|
||||
'info:Info about this project'
|
||||
'issues:Project issues tools'
|
||||
'network:Project network tools - sub-commands : web [user], list, fetch, commits'
|
||||
'open:Open the given user/project in a web browser'
|
||||
'pull-request:Generate the text for a pull request'
|
||||
'pull:Pull from a remote'
|
||||
'search:Search GitHub for the given repository name'
|
||||
'track:Track another users repository'
|
||||
)
|
||||
|
||||
local expl
|
||||
local -a pkgs installed_pkgs
|
||||
|
||||
_arguments \
|
||||
'*:: :->subcmds' && return 0
|
||||
|
||||
if (( CURRENT == 1 )); then
|
||||
_describe -t commands "github subcommand" _1st_arguments
|
||||
return
|
||||
fi
|
|
@ -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
|
||||
# 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
|
||||
|
||||
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
|
||||
}
|
||||
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
|
||||
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
|
||||
git init \
|
||||
|| return
|
||||
# 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 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,12 +53,12 @@ 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
|
||||
hub create \
|
||||
|| return
|
||||
git push -u origin master
|
||||
}
|
||||
|
||||
|
@ -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 #############################################################
|
||||
|
||||
|
|
Loading…
Reference in a new issue