Skip to end of metadata
Go to start of metadata

Imported From: http://groups.google.com/group/in-portal-resources/browse_thread/thread/105e37524ce69418#

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
http://www.debian-administration.org/article/An_introduction_to_bash_completion_part_1,
which explains magical ways how to make auto-complete work for you custom
commands.

--
Best Regards,

http://www.in-portal.com
http://www.alex-time.com

  • No labels

7 Comments

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

    DA

  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?

    DA

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

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

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

    }

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