Skip to end of metadata
Go to start of metadata

Imported From:

Did you use shell (e.g. bash) a lot?
Do you like pressing TAB to auto-complete any command you type?

If answer to both questions is yes, then read following article,
which explains magical ways how to make auto-complete work for you custom

Best Regards,

  • No labels


  1. We should do one for our do_update project to save time with guessing
    project name.


  2. Sure, but that requires knowledge of bash language.

  3. If I am not mistaken this is already done?

    By the way, I want to do this for my SSHA script which should auto-complete
    users same as SU - does.

    Can you help with this?


  4. Yes, this was done. Just place attached script under /etc/bash_completion.d

    You can easily create new auto-completion scripts based on attached one.
    I'll explain a bit how it works:

       - at top line function called "_do_update" is declared
       - within that function there is a switch statement for each of
       parameters (based on position)
       - at the end of the script "complete" command is called with script name
       (to be auto-completed) and function name, that is responsible for it.

    Make sure that you choose unique function name, because it's defined in
    global scope and is accessible to other completion scripts as well.

  5. Alex,

    I tried changing a bit your script to for myself so it lists users from
    current system, but can't get it work. Can you help?

    _ssha() {
    local cur opts

    case "${COMP_CWORD}" in
    COMPREPLY=( $( compgen -u -- "$cur" ) )


  6. I bet you needed to re-login for bash to re-read auto-completion scripts.