From 923b80bfebb29aa1187d9925be58625ca9bd0662 Mon Sep 17 00:00:00 2001 From: Robin Date: Sun, 1 Jan 2012 15:10:41 +0800 Subject: [PATCH] add bash completion support for git-gerrit. --- README.md | 32 ++++++++++- completion/git-gerrit-completion.bash | 81 +++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 completion/git-gerrit-completion.bash diff --git a/README.md b/README.md index 39dd7c3..19cabfa 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# gerrit Tools +# Gerrit Tools A few scripts to make code review via [Gerrit Code Review](http://gerrit.googlecode.com) easier for developers. They are improved and maintained to fit the needs of the [TYPO3](http://typo3.org) review workflow. @@ -179,6 +179,36 @@ It will print "git-gerrit can only be run from a git repository." in red (unless brew install https://raw.github.com/fbzhong/homebrew-library/master/Library/gerrit-tools.rb + +## Bash Completion + + Bash completion support for [git-gerrit](https://github.com/fbzhong/gerrit-tools) + +### Installation + + To achieve git-gerrit completion nirvana: + + 0. Install git-completion. + + 1. Install this file. Either: + + a. Place it in a `bash-completion.d` folder: + + * /etc/bash-completion.d + * /usr/local/etc/bash-completion.d + * ~/bash-completion.d + + b. Or, copy it somewhere (e.g. ~/.git-gerrit-completion.bash) and put the following line in + your .bashrc: + + source ~/.git-gerrit-completion.bash + + 2. If you are using Git < 1.7.1: Edit git-completion.sh and add the following line to the giant + $command case in _git: + + gerrit) _git_gerrit ;; + + ## Contributing Feel free to fork and send a pull request if you think you've improved anything. diff --git a/completion/git-gerrit-completion.bash b/completion/git-gerrit-completion.bash new file mode 100644 index 0000000..05e2c84 --- /dev/null +++ b/completion/git-gerrit-completion.bash @@ -0,0 +1,81 @@ +#!bash +# +# git-gerrit-completion +# =================== +# +# Bash completion support for [git-gerrit](https://github.com/fbzhong/gerrit-tools) +# +# +# Installation +# ------------ +# +# To achieve git-gerrit completion nirvana: +# +# 0. Install git-completion. +# +# 1. Install this file. Either: +# +# a. Place it in a `bash-completion.d` folder: +# +# * /etc/bash-completion.d +# * /usr/local/etc/bash-completion.d +# * ~/bash-completion.d +# +# b. Or, copy it somewhere (e.g. ~/.git-gerrit-completion.bash) and put the following line in +# your .bashrc: +# +# source ~/.git-gerrit-completion.bash +# +# 2. If you are using Git < 1.7.1: Edit git-completion.sh and add the following line to the giant +# $command case in _git: +# +# gerrit) _git_gerrit ;; +# +# +# The Fine Print +# -------------- +# +# Copyright (c) 2012 [Fubai Zhong](https://github.com/fbzhong) +# +# Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/) +# +# Credit +# -------------- +# +# Thank [Justin Hileman](http://justinhileman.com) for https://github.com/bobthecow/git-flow-completion/ +# + +_git_gerrit () +{ + local subcommands="init merge push changes apply reset update rebase diff review submit abandon" + local subcommand="$(__git_find_on_cmdline "$subcommands")" + if [ -z "$subcommand" ]; then + __gitcomp "$subcommands" + return + fi + + case "$subcommand" in + merge) + __git_gerrit_merge + return + ;; + *) + COMPREPLY=() + ;; + esac +} + +__git_gerrit_merge () +{ + __gitcomp "$(__git_gerrit_list_branches)" +} + +__git_gerrit_list_branches () +{ + git branch 2>/dev/null | grep -v '*' | sort +} + +# alias __git_find_on_cmdline for backwards compatibility +if [ -z "`type -t __git_find_on_cmdline`" ]; then + alias __git_find_on_cmdline=__git_find_subcommand +fi