← Thomas Lackemann

Auto-complete Aliases in Bash

Posted on Jul 30, 2016 in

I have a simple alias to copy passwords to the clipboard.

alias cpass='pass -c "$@"'

Pretty straight forward; however, I lose auto-complete which makes this alias pretty pointless. To fix this, I simply append the following to ~/.bashrc

# Autocomplete 'cpass'
_completion_loader pass
complete -F _pass cpass

Bash only loads an appropriate auto-complete function when the program is acted upon (e.g. entering pass <tab>) so we need to explicitly load the function for pass with _completion_loader pass. We then assign cpass the explicitly loaded function with complete -F _pass cpass.

That’s it! Feel free to use this for any of your aliases. You can find almost all auto-complete functions in /usr/share/bash-completion/completions/.



Tom is the CEO (Customer Experience Overlord) of Unicorn Heart Club where he leads development for Astral Virtual TableTop. He's a homebrewer, hiker, and has an about page.

Read More

← How I Use TaskWarrior to Stay Organized