Patching tool autocomplete for Bash

If, like me, you work on a non-Windows machine, an Apple MacBook Pro in my case with OSX, you are probably used to having TAB completion in your terminal. I've caught myself multiple times lately using TAB when working with the Liferay patching tool and then just getting a file listing instead if the list of possible commands. This is of course normal as the patching tool isn't a default OS level tool for which Bash has standard autocomplete support build in. As I'm not that good at remembering a lot of shortcuts/commands (seems like for every one I push in my brain an older one falls out) I decided to see if I could add autocompletion for the patching tool to Bash.

Some Googling showed that this shouldn't be that hard as we only need command completion, but not option/switch completion or other more complicated scenario's. The following information will be OSX specific, but except for the Homebrew parts, should easily translate to Linux based systems.

To add completion for Liferay's patching tool we'll need to use the Bash Programmable Completion project. On OSX this can be easily installed via a simple Homebrew command: brew install bash-completion.

Warning: You are using OS X 10.11.
We do not provide support for this pre-release version.
You may encounter build failures or other breakage.
==> Downloading https://bash-completion.alioth.debian.org/files/bash-completion-1.3.tar.bz2
######################################################################## 100.0%
==> Patching
patching file bash_completion
==> ./configure --prefix=/usr/local/Cellar/bash-completion/1.3
==> make install
==> Caveats
Add the following lines to your ~/.bash_profile:
  if [ -f $(brew --prefix)/etc/bash_completion ]; then
    . $(brew --prefix)/etc/bash_completion
  fi

Homebrew's own bash completion script has been installed to
  /usr/local/etc/bash_completion.d

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
�  /usr/local/Cellar/bash-completion/1.3: 188 files, 1.1M, built in 4 seconds

This will install the necessary stuff on your machine, but leaves 1 task to be done manually. You will need to add the following lines to your own .bash_profile file:

if [ -f $(brew --prefix)/etc/bash_completion ]; then
    . $(brew --prefix)/etc/bash_completion
fi

The next, and already last, step is to create a custom autocomplete script file with the name patching-tool.sh (remember to make it executable) in /usr/local/etc/bash_completion.d that has the following content (Gist): 

_patching-tool()
{
    local cur=${COMP_WORDS[COMP_CWORD]}
    COMPREPLY=( $(compgen -W "auto-discovery diff help index-info info install list-collisions list-customizations list-plugins revert server-status setup store support-info update-plugins version" -- $cur) )
}
complete -F _patching-tool patching-tool.sh

Once you have all this in place and reload your Bash profile you should have basic patching tool autocompletion like this:

Blogs
Still on bash Nate? What you really want is zsh - https://github.com/robbyrussell/oh-my-zsh ... get rid of your old bash on OSX:
on El Capitan (bash -version):
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15)
Copyright (C) 2007 Free Software Foundation, Inc.