Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as a developer

View project on GitHub

Implement tab completions

You can implement your own bash completions for commands you use alot to save on typing.

An example ackrc based on my TIL

This completion script, reads your $HOME/.ackrc files and offers tab completions for your custom types.

$ ack <tab>

An example ackrc based on my TIL


Would work as follows:

$ ack --<tab>
--mojo --conf

The complete implementation lifed from my github repository.

    local cur prev opts
    local opts=$(sed -n "s/--type-set=\([^']*\)=.*/--\1/p" $HOME/.ackrc )

    COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )

complete -F _ack ack

Since the tab completion is a programmatic implementation, there is a lot you can do to make your day to day work with bash easier.