Skip to content
Browse files

Add git flow completion support

  • Loading branch information...
1 parent b27cf60 commit 5f4d4ac04161d5a5bd945b8df174efc6315bb6e5 @spf13 committed May 5, 2010
Showing with 183 additions and 0 deletions.
  1. +19 −0 git.conf
  2. +1 −0 scripts/git-completion.sh
  3. +163 −0 scripts/git-flow-completion.sh
View
19 git.conf
@@ -1,4 +1,7 @@
source $PROFILE_PATH/scripts/git-completion.sh
+source $PROFILE_PATH/scripts/git-flow-completion.sh
+
+## ALIASES
alias gp='git push'
alias gl='git pull'
@@ -14,3 +17,19 @@ alias gxc='gitx -c'
alias gru='git remote update'
alias gsdc='git svn dcommit'
+
+## FUNCTIONS
+
+# cd relative to the current Git repo
+#
+# author: Justin Hileman (http://justinhileman.com)
+#
+# installation:
+# Add the following function to your `.bashrc` or `.bash_profile` file,
+# or save it somewhere (i.e. `~/.cdg.sh`) and source it in `.bashrc`
+#
+# usage:
+# cdg [path relative to git dir]
+cdg () {
+ [[ ! -z $(which git 2> /dev/null) ]] && [[ $(git status 2> /dev/null) ]] && cd "./$(git rev-parse --show-cdup)/$1"
+}
View
1 scripts/git-completion.sh
@@ -1343,6 +1343,7 @@ _git ()
svn) _git_svn ;;
tag) _git_tag ;;
whatchanged) _git_log ;;
+ flow) _git_flow ;;
*) COMPREPLY=() ;;
esac
}
View
163 scripts/git-flow-completion.sh
@@ -0,0 +1,163 @@
+#!bash
+#
+# git-flow-completion
+# ===================
+#
+# Bash completion support for [git-flow](http://github.com/nvie/gitflow)
+#
+# The contained completion routines provide support for completing:
+#
+# * git-flow init and version
+# * feature, hotfix and release branches
+# * remote feature branch names (for `git-flow feature track`)
+#
+#
+# Installation
+# ------------
+#
+# To achieve git-flow 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-flow-completion.sh) and put the following line in
+# your .bashrc:
+#
+# source ~/.git-flow-completion.sh
+#
+# 3. Edit git-completion.sh and add the following line to the giant $command case in _git:
+#
+# flow) _git_flow ;;
+#
+#
+# Requirement 3 will go away as soon as I figure out how to properly (and predictably) hijack
+# the `complete -F` ownership for `git` without breaking regular `git-completion`...
+#
+#
+#
+# The Fine Print
+# --------------
+#
+# Copyright (c) 2010 [Justin Hileman](http://justinhileman.com)
+#
+# Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/)
+
+_git_flow ()
+{
+ local subcommands="init feature release hotfix"
+ local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ if [ -z "$subcommand" ]; then
+ __gitcomp "$subcommands"
+ return
+ fi
+
+ case "$subcommand" in
+ feature)
+ __git_flow_feature
+ return
+ ;;
+ release)
+ __git_flow_release
+ return
+ ;;
+ hotfix)
+ __git_flow_hotfix
+ return
+ ;;
+ *)
+ COMPREPLY=()
+ ;;
+ esac
+}
+
+__git_flow_feature ()
+{
+ local subcommands="list start finish publish track diff rebase"
+ local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ if [ -z "$subcommand" ]; then
+ __gitcomp "$subcommands"
+ return
+ fi
+
+ case "$subcommand" in
+ finish|publish|diff|rebase)
+ __gitcomp "$(__git_flow_list_features)"
+ return
+ ;;
+ track)
+ __gitcomp "$(__git_flow_list_remote_features)"
+ return
+ ;;
+ *)
+ COMPREPLY=()
+ ;;
+ esac
+}
+
+__git_flow_list_features ()
+{
+ git flow feature list 2> /dev/null
+}
+
+__git_flow_list_remote_features ()
+{
+ git branch -r 2> /dev/null | grep 'origin/feature/' | awk '{ sub(/^origin\/feature\//, "", $1); print }'
+}
+
+__git_flow_release ()
+{
+ local subcommands="list start finish"
+ local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ if [ -z "$subcommand" ]; then
+ __gitcomp "$subcommands"
+ return
+ fi
+
+ case "$subcommand" in
+ finish)
+ __gitcomp "$(__git_flow_list_releases)"
+ return
+ ;;
+ *)
+ COMPREPLY=()
+ ;;
+ esac
+
+}
+
+__git_flow_list_releases ()
+{
+ git flow release list 2> /dev/null
+}
+
+__git_flow_hotfix ()
+{
+ local subcommands="list start finish"
+ local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ if [ -z "$subcommand" ]; then
+ __gitcomp "$subcommands"
+ return
+ fi
+
+ case "$subcommand" in
+ finish)
+ __gitcomp "$(__git_flow_list_hotfixes)"
+ return
+ ;;
+ *)
+ COMPREPLY=()
+ ;;
+ esac
+}
+
+__git_flow_list_hotfixes ()
+{
+ git flow hotfix list 2> /dev/null
+}

0 comments on commit 5f4d4ac

Please sign in to comment.
Something went wrong with that request. Please try again.