Created
May 2, 2015 00:56
-
-
Save mattiasb/ccf611e78afb781e5f4f to your computer and use it in GitHub Desktop.
Current snapshot of git-spindle.completion.bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright ⓒ 2015 Mattias Bengtsson | |
# | |
# git-spindle is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# git-spindle is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with git-spindle. If not, see <http://www.gnu.org/licenses/>. | |
# | |
# Author: Mattias Bengtsson <[email protected]> | |
_git_hub () { | |
local subcommands="add-account \ | |
add-hook \ | |
add-public-keys \ | |
add-remote \ | |
apply-pr \ | |
browse \ | |
calendar \ | |
cat \ | |
clone \ | |
config \ | |
create \ | |
edit-hook \ | |
fork \ | |
forks \ | |
gist \ | |
gists \ | |
hooks \ | |
ignore \ | |
issue \ | |
issues \ | |
log \ | |
ls \ | |
mirror \ | |
network \ | |
public-keys \ | |
pull-request \ | |
remove-hook \ | |
render \ | |
repos \ | |
say \ | |
set-origin \ | |
setup-goblet \ | |
status \ | |
whoami \ | |
whois " | |
local subcommand="$(__git_find_on_cmdline "$subcommands")" | |
if [ -z "$subcommand" ]; then | |
__gitcomp "$subcommands" | |
return | |
fi | |
case "$subcommand" in | |
add-account) | |
_git_hub_add_account | |
;; | |
add-hook) | |
_git_hub_add_hook | |
;; | |
add-public-keys) | |
_git_hub_add_public_keys | |
;; | |
add-remote) | |
_git_hub_add_remote | |
;; | |
apply-pr) | |
_git_hub_apply_pr | |
;; | |
browse) | |
_git_hub_browse | |
;; | |
calendar) | |
_git_hub_calendar | |
;; | |
cat) | |
_git_hub_cat | |
;; | |
clone) | |
_git_hub_clone | |
;; | |
config) | |
_git_hub_config | |
;; | |
create) | |
_git_hub_create | |
;; | |
edit-hook) | |
_git_hub_edit_hook | |
;; | |
fork) | |
_git_hub_fork | |
;; | |
forks) | |
_git_hub_forks | |
;; | |
gist) | |
_git_hub_gist | |
;; | |
gists) | |
_git_hub_gists | |
;; | |
hooks) | |
_git_hub_hooks | |
;; | |
ignore) | |
_git_hub_ignore | |
;; | |
issue) | |
_git_hub_issue | |
;; | |
issues) | |
_git_hub_issues | |
;; | |
log) | |
_git_hub_log | |
;; | |
ls) | |
_git_hub_ls | |
;; | |
mirror) | |
_git_hub_mirror | |
;; | |
network) | |
_git_hub_network | |
;; | |
public-keys) | |
_git_hub_public_keys | |
;; | |
pull-request) | |
_git_hub_pull_request | |
;; | |
remove-hook) | |
_git_hub_remove_hook | |
;; | |
render) | |
_git_hub_render | |
;; | |
repos) | |
_git_hub_repos | |
;; | |
say) | |
_git_hub_say | |
;; | |
set-origin) | |
_git_hub_set_origin | |
;; | |
setup-goblet) | |
_git_hub_setup_goblet | |
;; | |
status) | |
_git_hub_status | |
;; | |
whoami) | |
_git_hub_whoami | |
;; | |
whois) | |
_git_hub_whois | |
;; | |
*) | |
COMPREPLY=() | |
;; | |
esac | |
} | |
########### | |
# HELPERS # | |
########### | |
# I have yet to find out how to make bash completion not fallback to file | |
# completion when returning an empty COMPREPLY. | |
# As a workaround return a COMPREPLY with one element: the empty string and | |
# echo the bel character. | |
__no_file_fallback () { | |
echo -en "\a" | |
COMPREPLY=( '' ) | |
} | |
function __gitcompappend_once { | |
[ -z "${1}" ] && return -1 | |
if [ -z "$(__git_find_on_cmdline "${1}")" ]; then | |
__gitcompappend "${1}" "" "$cur" " " | |
return 0 | |
fi | |
return -1 | |
} | |
function __gitcomp_once { | |
COMPREPLY=() | |
__gitcompappend_once "$@" | |
} | |
############ | |
# COMMANDS # | |
############ | |
# git hub add-account [--host=<host>] <alias> | |
function _git_hub_add_account () { | |
case "$cur" in | |
--*) | |
__gitcomp_once "--host=" | |
return | |
;; | |
*) | |
__no_file_fallback | |
return | |
esac | |
} | |
# git hub add-hook <name> [<setting>...] | |
function _git_hub_add_hook () { | |
# TODO: Read up on this | |
__no_file_fallback | |
} | |
# git hub add-public-keys [<key>...] | |
function _git_hub_add_public_keys () { | |
return | |
} | |
# git hub add-remote [--ssh|--http|--git] <user>... | |
function _git_hub_add_remote () { | |
# TODO: Complete starred users | |
case "$cur" in | |
--*) | |
__gitcomp_once "--ssh --http --git" | |
return | |
;; | |
*) | |
__no_file_fallback | |
return | |
esac | |
} | |
# git hub apply-pr <pr-number> | |
function _git_hub_apply_pr () { | |
# TODO: complete PR's | |
__no_file_fallback | |
} | |
# git hub browse [--parent] [<repo>] [<section>] | |
function _git_hub_browse () { | |
case "$cur" in | |
--*) | |
__gitcomp_once "--parent" | |
return | |
;; | |
*) | |
case "$prev" in | |
browse|--parent) | |
# TODO: auto-complete starred/followed repos | |
__no_file_fallback | |
return | |
;; | |
*) | |
__gitcomp_once "issues \ | |
pulls \ | |
wiki \ | |
branches \ | |
releases \ | |
contributors \ | |
graphs \ | |
releases \ | |
settings " || __no_file_fallback | |
esac | |
return | |
esac | |
} | |
# git hub calendar [<user>] | |
function _git_hub_calendar () { | |
# TODO: auto-complete starred users | |
__no_file_fallback | |
} | |
# git hub cat <file>... | |
function _git_hub_cat () { | |
# TODO: either complete files from top-dir /or/ from repo | |
return | |
} | |
# git hub clone [--ssh|--http|--git] | |
# [--parent] | |
# [git-clone-options] <repo> [<dir>] | |
function _git_hub_clone () { | |
case "$cur" in | |
--*) | |
_git_clone | |
__gitcompappend_once "--ssh --http --git" | |
__gitcompappend_once "--parent" | |
return | |
;; | |
*) | |
# TODO: Complete starred/follows repos | |
__no_file_fallback | |
return | |
esac | |
} | |
# git hub config [--unset] <key> [<value>] | |
function _git_hub_config () { | |
case "$cur" in | |
--*) | |
__gitcomp_once "--unset" | |
return | |
;; | |
*) | |
# TODO: Investigate if keys and values can be completed | |
__no_file_fallback | |
return | |
esac | |
} | |
# git hub create [--private] [-d <description>] | |
function _git_hub_create () { | |
case "$cur" in | |
-*) | |
__gitcompappend_once "-d" | |
__gitcompappend_once "--private" | |
return | |
;; | |
--*) | |
__gitcompappend_once "--private" | |
return | |
;; | |
*) | |
__no_file_fallback | |
return | |
esac | |
} | |
# git hub edit-hook <name> [<setting>...] | |
function _git_hub_edit_hook () { | |
# TODO: Read up on this | |
__no_file_fallback | |
} | |
# git hub fork [--ssh|--http|--git] [<repo>] | |
function _git_hub_fork () { | |
case "$cur" in | |
--*) | |
__gitcomp_once "--ssh --http --git" | |
return | |
;; | |
*) | |
__no_file_fallback | |
return | |
esac | |
} | |
function _git_hub_forks () { | |
__no_file_fallback | |
} | |
# git hub gist [-d <description>] <file>... | |
function _git_hub_gist () { | |
case "$cur" in | |
-*) | |
__gitcomp_once "-d" | |
return | |
;; | |
*) | |
return | |
esac | |
return | |
} | |
# git hub gists [<user>] | |
function _git_hub_gists () { | |
# TODO: See if we can complete starred users here | |
__no_file_fallback | |
} | |
function _git_hub_hooks () { | |
# TODO: Read up on this | |
__no_file_fallback | |
} | |
# git hub ignore [<language>...] | |
function _git_hub_ignore () { | |
if [ -z "${__git_hub_ignore_cache}" ]; then | |
__git_hub_ignore_cache="$(git hub ignore | sed -n -e 's/ \* //p')" | |
fi | |
__gitcomp_nl "${__git_hub_ignore_cache}" | |
} | |
# git hub issue [<repo>] [--parent] [<issue>...] | |
function _git_hub_issue () { | |
# TODO: Read up on this | |
case "$cur" in | |
--*) | |
__gitcomp_once "--parent" | |
return | |
;; | |
*) | |
__no_file_fallback | |
return | |
esac | |
} | |
# git hub issues [<repo>] [--parent] [<filter>...] | |
function _git_hub_issues () { | |
# TODO: Read up on this | |
case "$cur" in | |
--*) | |
__gitcomp "--parent" | |
return | |
;; | |
*) | |
__no_file_fallback | |
return | |
esac | |
} | |
# git hub log [--type=<type>] [<what>] | |
function _git_hub_log () { | |
case "$cur" in | |
"--type=") | |
# TODO: complete the types | |
__no_file_fallback | |
return | |
;; | |
--*) | |
__gitcomp "--type=" | |
return | |
;; | |
*) | |
__no_file_fallback | |
return | |
esac | |
} | |
function _git_hub_ls () { | |
# TODO: either complete files from top-dir /or/ from repo | |
return | |
} | |
# git hub mirror [--ssh|--http|--git] [--goblet] [<repo>] | |
function _git_hub_mirror () { | |
# TODO: Check of [<repo>] refers to a repo on the fs or on GH, if the former | |
# then fs-complete | |
case "$cur" in | |
--*) | |
__gitcomp "--ssh --http --git --goblet" | |
return | |
;; | |
*) | |
__no_file_fallback | |
return | |
esac | |
} | |
# git hub network [<level>] | |
function _git_hub_network () { | |
__no_file_fallback | |
} | |
# git hub public-keys [<user>] | |
function _git_hub_public_keys () { | |
# TODO: look up what this command does | |
__no_file_fallback | |
} | |
# git hub pull-request [--issue=<issue>] [<branch1:branch2>] | |
function _git_hub_pull_request () { | |
# TODO: Consider completing issuenumber | |
# TODO: Complete branches. Should be remote branches | |
case "$cur" in | |
--*) | |
__gitcomp "--issue=" | |
return | |
;; | |
*) | |
__no_file_fallback | |
return | |
esac | |
} | |
# git hub remove-hook <name> | |
function _git_hub_remove_hook () { | |
# TODO: Consider completing hook name | |
__no_file_fallback | |
} | |
# git hub render [--save=<outfile>] <file> | |
function _git_hub_render () { | |
# TODO: Complete only .md files | |
case "$cur" in | |
--*) | |
__gitcomp "--save=" | |
return | |
;; | |
*) | |
return | |
esac | |
} | |
# git hub repos [--no-forks] [<user>] | |
function _git_hub_repos () { | |
# TODO: Complete starred user | |
case "$cur" in | |
--*) | |
__gitcomp "--no-forks" | |
return | |
;; | |
*) | |
__no_file_fallback | |
return | |
esac | |
} | |
# git hub say [<msg>] | |
function _git_hub_say () { | |
__no_file_fallback | |
} | |
# git hub set-origin [--ssh|--http|--git] | |
function _git_hub_set_origin () { | |
case "$cur" in | |
--*) | |
__gitcomp "--ssh --http --git" | |
return | |
;; | |
*) | |
__no_file_fallback | |
return | |
esac | |
} | |
# git hub setup-goblet | |
function _git_hub_setup_goblet () { | |
__no_file_fallback | |
} | |
# git hub status | |
function _git_hub_status () { | |
__no_file_fallback | |
} | |
# git hub whoami | |
function _git_hub_whoami () { | |
__no_file_fallback | |
} | |
# git hub whois <user>... | |
function _git_hub_whois () { | |
# TODO: Complete starred users | |
__no_file_fallback | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment