Skip to content

Commit

Permalink
add bash completion support for git-gerrit.
Browse files Browse the repository at this point in the history
  • Loading branch information
fbzhong committed Jan 1, 2012
1 parent 0f2ef9c commit 923b80b
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 1 deletion.
32 changes: 31 additions & 1 deletion 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.
Expand Down Expand Up @@ -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.
81 changes: 81 additions & 0 deletions 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

0 comments on commit 923b80b

Please sign in to comment.