til

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>
--yourcustomtype

An example ackrc based on my TIL

--type-set=mojo=.css,.pl,.pm,.html,.js,.tt,.ep,.conf
--type-set=conf=.conf

Would work as follows:

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

The complete implementation lifed from my github repository.

_ack()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    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.