ACA Blog

ACA Blog


October 2019
M T W T F S S
« Sep    
 123456
78910111213
14151617181920
21222324252627
28293031  

Categories


Patching tool autocomplete for Bash

Jan EerdekensJan Eerdekens

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.

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:

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):

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

bash-completion

Belgian Java and Liferay developer with some weird interests, eternal complainer, atheist, skeptic and geocacher.