in reply to (OT) Bash Tabbing

You should look through the documentation for the bash completion project. It's very flexible, but I can't recall offhand if it does what you want.

Replies are listed 'Best First'.
Re^2: (OT) Bash Tabbing
by imp (Priest) on Aug 24, 2006 at 07:08 UTC
    If you want to customize the completion on a per-script basis, then one way to approach this problem would be to use bash_completion with a custom completion function. This function could parse the given perl script for completion hints which could be passed to compgen (a bash builtin).

    I haven't worked with bash_completion enough to provide a working example unfortunately. One potential shortcoming would be that you need to tell bash when to run this completion code. This is typically done by specifying the completion logic for a given command. (e.g. perl is handled by the _perl function).

    Example code with completion config in comments

    #!/usr/bin/perl #complete -G '*.bak'
    And awk to extract it:
    awk 'NR == 1 {next} /^\#complete/ {print} /^[^#]/ {exit}' $filename
    Explanation of the awk:
    1. NR == 1 {next}
      Skip the first record
    2. /^\#complete/ {print}
      Print any lines that start with #complete
    3. /^^#/ {exit}
      Stop processing when a non-comment line is reached