From 287f1a570fa5892c8103d746a7d884a1fcf7ce88 Mon Sep 17 00:00:00 2001 From: Weiyan Shao Date: Wed, 4 Sep 2013 23:08:56 +0200 Subject: [PATCH 1/7] added auto-completion for hub from GitHub --- src/_hub | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 src/_hub diff --git a/src/_hub b/src/_hub new file mode 100644 index 0000000..df09ace --- /dev/null +++ b/src/_hub @@ -0,0 +1,160 @@ +#compdef hub + +# Zsh will source this file when attempting to autoload the "_hub" function, +# typically on the first attempt to complete the hub command. We define two new +# setup helper routines (one for the zsh-distributed version, one for the +# git-distributed, bash-based version). Then we redefine the "_hub" function to +# call "_git" after some other interception. +# +# This is pretty fragile, if you think about it. Any number of implementation +# changes in the "_git" scripts could cause problems down the road. It would be +# better if the stock git completions were just a bit more permissive about how +# it allowed third-party commands to be added. + +(( $+functions[__hub_setup_zsh_fns] )) || +__hub_setup_zsh_fns () { + (( $+functions[_git-alias] )) || + _git-alias () { + _arguments \ + '-s[output shell script suitable for eval]' \ + '1::shell:(zsh bash csh)' + } + + (( $+functions[_git-browse] )) || + _git-browse () { + _arguments \ + '-u[output the URL]' \ + '2::subpage:(wiki commits issues)' + } + + (( $+functions[_git-compare] )) || + _git-compare () { + _arguments \ + '-u[output the URL]' \ + ':[start...]end range:' + } + + (( $+functions[_git-create] )) || + _git-create () { + _arguments \ + '::name (REPOSITORY or ORGANIZATION/REPOSITORY):' \ + '-p[make repository private]' \ + '-d[description]:description' \ + '-h[home page]:repository home page URL:_urls' + } + + (( $+functions[_git-fork] )) || + _git-fork () { + _arguments \ + '--no-remote[do not add a remote for the new fork]' + } + + (( $+functions[_git-pull-request] )) || + _git-pull-request () { + _arguments \ + '-f[force (skip check for local commits)]' \ + '-b[base]:base ("branch", "owner\:branch", "owner/repo\:branch"):' \ + '-h[head]:head ("branch", "owner\:branch", "owner/repo\:branch"):' \ + - set1 \ + '-m[message]' \ + '-F[file]' \ + - set2 \ + '-i[issue]:issue number:' \ + - set3 \ + '::issue-url:_urls' + } + + # stash the "real" command for later + functions[_hub_orig_git_commands]=$functions[_git_commands] + + # Replace it with our own wrapper. + declare -f _git_commands >& /dev/null && unfunction _git_commands + _git_commands () { + local ret=1 + # call the original routine + _call_function ret _hub_orig_git_commands + + # Effectively "append" our hub commands to the behavior of the original + # _git_commands function. Using this wrapper function approach ensures + # that we only offer the user the hub subcommands when the user is + # actually trying to complete subcommands. + 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' + ci-status:'lookup commit in GitHub Status API' + ) + _describe -t hub-commands 'hub command' hub_commands && ret=0 + + return ret + } +} + +(( $+functions[__hub_setup_bash_fns] )) || +__hub_setup_bash_fns () { + # TODO more bash-style fns needed here to complete subcommand args. They take + # the form "_git_CMD" where "CMD" is something like "pull-request". + + # Duplicate and rename the 'list_all_commands' function + eval "$(declare -f __git_list_all_commands | \ + sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')" + + # Wrap the 'list_all_commands' function with extra hub commands + __git_list_all_commands() { + cat <<-EOF +alias +pull-request +fork +create +browse +compare +ci-status +EOF + __git_list_all_commands_without_hub + } + + # Ensure cached commands are cleared + __git_all_commands="" +} + +# redefine _hub to a much smaller function in the steady state +_hub () { + # only attempt to intercept the normal "_git" helper functions once + (( $+__hub_func_replacement_done )) || + () { + # At this stage in the shell's execution the "_git" function has not yet + # been autoloaded, so the "_git_commands" or "__git_list_all_commands" + # functions will not be defined. Call it now (with a bogus no-op service + # to prevent premature completion) so that we can wrap them. + if declare -f _git >& /dev/null ; then + _hub_noop () { __hub_zsh_provided=1 } # zsh-provided will call this one + __hub_noop_main () { __hub_git_provided=1 } # git-provided will call this one + local service=hub_noop + _git + unfunction _hub_noop + unfunction __hub_noop_main + service=git + fi + + if (( $__hub_zsh_provided )) ; then + __hub_setup_zsh_fns + elif (( $__hub_git_provided )) ; then + __hub_setup_bash_fns + fi + + __hub_func_replacement_done=1 + } + + # Now perform the actual completion, allowing the "_git" function to call our + # replacement "_git_commands" function as needed. Both versions expect + # service=git or they will call nonexistent routines or end up in an infinite + # loop. + service=git + declare -f _git >& /dev/null && _git +} + +# make sure we actually attempt to complete on the first "tab" from the user +_hub From 1485f81a8cb180a13825118bbb3122b440f0d3b1 Mon Sep 17 00:00:00 2001 From: Weiyan Shao Date: Wed, 4 Sep 2013 23:29:33 +0200 Subject: [PATCH 2/7] hello --- src/_ag | 1 - src/_gem | 1 - 2 files changed, 2 deletions(-) diff --git a/src/_ag b/src/_ag index 0f61fc2..bf6c5e5 100644 --- a/src/_ag +++ b/src/_ag @@ -11,7 +11,6 @@ # # * Akira Maeda # -# ------------------------------------------------------------------------------ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------ diff --git a/src/_gem b/src/_gem index 5870928..467cf03 100644 --- a/src/_gem +++ b/src/_gem @@ -17,7 +17,6 @@ _gem() { - local -a gem_general_flags local context curcontext="$curcontext" update_policy From 0c9021e66202f2728e4480023d50b60ffcbf22dc Mon Sep 17 00:00:00 2001 From: Weiyan Shao Date: Wed, 4 Sep 2013 23:33:16 +0200 Subject: [PATCH 3/7] Revert "hello" This reverts commit 1485f81a8cb180a13825118bbb3122b440f0d3b1. --- src/_ag | 1 + src/_gem | 1 + 2 files changed, 2 insertions(+) diff --git a/src/_ag b/src/_ag index bf6c5e5..0f61fc2 100644 --- a/src/_ag +++ b/src/_ag @@ -11,6 +11,7 @@ # # * Akira Maeda # +# ------------------------------------------------------------------------------ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------ diff --git a/src/_gem b/src/_gem index 467cf03..5870928 100644 --- a/src/_gem +++ b/src/_gem @@ -17,6 +17,7 @@ _gem() { + local -a gem_general_flags local context curcontext="$curcontext" update_policy From fe529dce63968ebe12057254f7382d310dea087c Mon Sep 17 00:00:00 2001 From: Syohei YOSHIDA Date: Thu, 5 Sep 2013 12:42:09 +0900 Subject: [PATCH 4/7] add newly options --- src/_cpanm | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/_cpanm b/src/_cpanm index a1a6210..3ebe547 100644 --- a/src/_cpanm +++ b/src/_cpanm @@ -28,29 +28,53 @@ arguments=( '(- :)--info[Displays distribution info on CPAN]' '(--installdeps)--installdeps[Only install dependencies]' '(--look)--look[Download/unpack the distribution and then open the directory with your shell]' + '(--uninstall -U)'{--uninstall,-U}'[Uninstalls the modules]' '(- :)'{--help,-h}'[Displays help information]' '(- :)'{--version,-V}'[Displays software version]' # Options {--force,-f}'[Force install]' {--notest,-n}'[Do not run unit tests]' + '(--test-only)--test-only[Run the test only and do not install the module]' {--sudo,-S}'[sudo to run install commands]' '(-v --verbose --quiet -q)'{--verbose,-v}'[Turns on chatty output]' '(-q --quiet --verbose -v)'{--quiet,-q}'[Turns off all output]' {--local-lib,-l}'[Specify the install base to install modules]' {--local-lib-contained,-L}'[Specify the install base to install all non-core modules]' + '(--self-contained)--self-contained[Assume no non-core modules are installed on the system]' '--mirror[Specify the base URL for the mirror (e.g. http://cpan.cpantesters.org/)]:URLs:_urls' '--mirror-only[Use the mirror\''s index file instead of the CPAN Meta DB]' + '--mirror-index[Specifies the file path for module search index]:FILES:_files' '--prompt[Prompt when configure/build/test fails]' + '(--dev)--dev[Search for a newer developer release as well]' '--reinstall[Reinstall the distribution even if you already have the latest version installed]' '--interactive[Turn on interactive configure]' + '(--pp --pureperl)'{--pp,--pureperl}'[Prefer Pure perl build of modules]' + '(--with-recommends)--with-recommends[Installs dependencies declared as "recommends"]' + '(--with-suggests)--with-suggests[Installs dependencies declared as "suggests"]' + '(--with-feature)--with-feature[Specifies the feature to enable]' + '(--without-feature)--without-feature[Specifies the feature to disable]' + '(--with-all-features)--with-all-features[Enables all the optional features]' + '(--configure-timeout)--configure-timeout[Specify the timeout length to wait for configure]' + '(--build-timeout)--build-timeout[Specify the timeout length to wait for build]' + '(--test-timeout)--test-timeout[Specify the timeout length to wait for test]' + '(--configure-args)--configure-args[Pass arguments for configure commands]' + '(--build-args)--build-args[Pass arguments for build commands]' + '(--test-args)--test-args[Pass arguments for test commands]' + '(--install-args)--install-args[Pass arguments for install commands]' '--scandeps[Scan the depencencies of given modules and output the tree in a text format]' '--format[Specify what format to display the scanned dependency tree]:scandeps format:(tree json yaml dists)' '--save-dists[Specify the optional directory path to copy downloaded tarballs]' -# '--uninst-shadows[Uninstalls the shadow files of the distribution that you\''re installing]' + '(--uninst-shadows)--uninst-shadows[Uninstalls the shadow files of the distribution that you\''re installing]' + '(--cascade-search)--cascade-search[Specifies whether to cascade search]' + '(--skip-installed)--skip-installed[Specifies modules which lastet version are already installed]' + '(--skip-satisfied)--skip-satisfied[Specifies module and version for skipping installation]' + '(--verify)--verify[Verify the integrity of distribution files]' + '(--no-report-perl-version)--report-perl-version[Report locally installed perl version as part of User-Agent]' + '(--report-perl-version)--no-report-perl-version[Disable --report-perl-version]' '--auto-cleanup[Number of days that cpanm\''s work directories expire in. Defaults to 7]' '(--no-man-pages)--man-pages[Generates man pages for executables (man1) and libraries (man3)]' '(--man-pages)--no-man-pages[Do not generate man pages]' From 356ffb220e7f7e468bbe204755ef2fc42a940850 Mon Sep 17 00:00:00 2001 From: Greg Sieranski Date: Thu, 5 Sep 2013 11:01:29 -0400 Subject: [PATCH 5/7] add audit command to homebrew tab completion --- src/_brew | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_brew b/src/_brew index 3940c05..069523a 100644 --- a/src/_brew +++ b/src/_brew @@ -40,7 +40,7 @@ _brew_outdated_formulae() { local -a _1st_arguments _1st_arguments=( - 'audit:check formulae for Homebrew coding style violations' + 'audit:check formulae for Homebrew coding style' 'cat:display formula file for a formula' 'cleanup:uninstall unused and old versions of packages' 'create:create a new formula' @@ -114,7 +114,7 @@ case "$words[1]" in _brew_installed_formulae _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae fi ;; - install|home|homepage|log|info|abv|uses|cat|deps|edit|options) + install|audit|home|homepage|log|info|abv|uses|cat|deps|edit|options) _brew_all_formulae _wanted formulae expl 'all formulae' compadd -a formulae ;; remove|rm|uninstall|unlink|cleanup|link|ln|pin|unpin|test) From 0746bc5a29b02e003e4bfe32f70002c7b78b9947 Mon Sep 17 00:00:00 2001 From: Weiyan Shao Date: Wed, 18 Sep 2013 15:35:43 +0200 Subject: [PATCH 6/7] add hub completion Add hub completion provided by github added copyright information --- src/_hub | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/_hub b/src/_hub index df09ace..736a147 100644 --- a/src/_hub +++ b/src/_hub @@ -1,5 +1,30 @@ #compdef hub +# This software is originally obtained from +# https://github.com/github/hub/blob/master/etc/hub.zsh_completion +# This software is released under MIT License as follows: + +# Copyright (c) 2009 Chris Wanstrath + +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# # Zsh will source this file when attempting to autoload the "_hub" function, # typically on the first attempt to complete the hub command. We define two new # setup helper routines (one for the zsh-distributed version, one for the From 05c8e87c2a1b5e13684dcee07258e997c9dde86c Mon Sep 17 00:00:00 2001 From: Akira Maeda Date: Thu, 5 Sep 2013 20:23:51 +0900 Subject: [PATCH 7/7] add gist completion --- src/_gist | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/_gist diff --git a/src/_gist b/src/_gist new file mode 100644 index 0000000..138e30b --- /dev/null +++ b/src/_gist @@ -0,0 +1,41 @@ +#compdef gist +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# Completion script for gist (https://github.com/defunkt/gist) +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Akira Maeda +# +# ------------------------------------------------------------------------------ +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------ + +local curcontext="$curcontext" state line ret=1 +typeset -A opt_args + +_arguments -C \ + '(--login)--login[Authenticate gist on this computer.]' \ + '(-f --filename)'{-f,--filename}'[Sets the filename and syntax type.]:NAME' \ + '(-t --type)'{-t,--type}'[Sets the file extension and syntax type.]:EXT' \ + '(-p --private)'{-p,--private}'[Makes your gist private.]' \ + '(--no-private)'--no-private'[Makes your gist no private.]' \ + '(-d --description)'{-d,--description}'[Adds a description to your gist.]:DESCRIPTION' \ + '(-s --shorten)'{-s,--shorten}'[Shorten the gist URL using git.io.]' \ + '(-u --update)'{-u,--update}'[Update an existing gist.]:URL ID' \ + '(-a --anonymous)'{-a,--anonymous}'[Create an anonymous gist.]' \ + '(-c --copy)'{-c,--copy}'[Copy the resulting URL to the clipboard]' \ + '(-e --embed)'{-e,--embed}'[Copy the embed code for the gist to the clipboard]' \ + '(-o --open)'{-o,--open}'[Open the resulting URL in a browser]' \ + '(--no-open)'--no-open'[No open the resulting URL in a browser]' \ + '(-P --paste)'{-P,--paste}'[Paste from the clipboard to gist]' \ + '(-h --help)'{-h,--help}'[print options help]' \ + '(-v --version)'{-v,--version}'[print version]' \ + '*: :_files' && ret=0 + +return ret