How can i list my arguments while pressing tab? - Unix

This is a discussion on How can i list my arguments while pressing tab? - Unix ; Actually i wrote a bash script which accepts 5 positional parameter one at a time. My requirement is, if the user press tab then i have to display the arguments. How can i do this?...

+ Reply to Thread
Results 1 to 7 of 7

Thread: How can i list my arguments while pressing tab?

  1. How can i list my arguments while pressing tab?

    Actually i wrote a bash script which accepts 5 positional parameter
    one at a time.
    My requirement is, if the user press tab then i have to display the
    arguments.
    How can i do this?


  2. Re: How can i list my arguments while pressing tab?

    On Sat, 03 Nov 2007 02:33:38 -0700, lak wrote:

    > Actually i wrote a bash script which accepts 5 positional parameter one
    > at a time.
    > My requirement is, if the user press tab then i have to display the
    > arguments.
    > How can i do this?


    Never used it, but bash completion comes to mind.

    http://www.caliban.org/bash/index.shtml#completion

  3. Re: How can i list my arguments while pressing tab?

    On Nov 3, 4:48 pm, Brian Szmyd wrote:
    > On Sat, 03 Nov 2007 02:33:38 -0700, lak wrote:
    > > Actually i wrote a bash script which accepts 5 positional parameter one
    > > at a time.
    > > My requirement is, if the user press tab then i have to display the
    > > arguments.
    > > How can i do this?

    >
    > Never used it, but bash completion comes to mind.
    >
    > http://www.caliban.org/bash/index.shtml#completion


    I really don't know if a bash (or any shell) script can react on the
    TAB key. That would require non-buffered read functions, which I think
    bash doesn't have. It's read is based on buffered reading, which
    requires the ENTER key after typing. Maybe you should switch to C?

    Darko


  4. Re: How can i list my arguments while pressing tab?

    On 2007-11-03, lak wrote:
    >
    >
    > Actually i wrote a bash script which accepts 5 positional parameter
    > one at a time.


    The positional parameters are all on the command line
    simultaneously. Do you mean "uses them one at a time"?

    > My requirement is, if the user press tab then i have to display the
    > arguments.
    > How can i do this?


    read -sn1
    case $REPLY in
    $'\t') printf "%s\n" "$@" ;;
    esac


    --
    Chris F.A. Johnson, author |
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence

  5. Re: How can i list my arguments while pressing tab?

    On Sun, 04 Nov 2007 15:15:24 +0000, Darko wrote:

    > On Nov 3, 4:48 pm, Brian Szmyd wrote:
    >> On Sat, 03 Nov 2007 02:33:38 -0700, lak wrote:
    >> > Actually i wrote a bash script which accepts 5 positional parameter
    >> > one at a time.
    >> > My requirement is, if the user press tab then i have to display the
    >> > arguments.
    >> > How can i do this?

    >>
    >> Never used it, but bash completion comes to mind.
    >>
    >> http://www.caliban.org/bash/index.shtml#completion

    >
    > I really don't know if a bash (or any shell) script can react on the TAB
    > key. That would require non-buffered read functions, which I think bash
    > doesn't have. It's read is based on buffered reading, which requires the
    > ENTER key after typing. Maybe you should switch to C?
    >
    > Darko


    A BASH completion script would be a script that BASH would execute on TAB
    key when it recognized the executable name of the bash script. Many
    applications have these (e.g. tar). When the TAB key is pressed, BASH
    looks for a matching completion script for the command and executes
    it...though I don't know how flexible it is aside from doing things like
    filename completion.

  6. Re: How can i list my arguments while pressing tab?

    On 3 Nov, 09:33, lak wrote:
    > Actually i wrote a bash script which accepts 5 positional parameter
    > one at a time.
    > My requirement is, if the user press tab then i have to display the
    > arguments.
    > How can i do this?


    The following will do what you want....but I really suggest it
    would be better to display the usage in response to an invocation
    with -? or -h or --help or --usage. That is much more standard.
    In the following, I display all the arguments at once. If you
    want to print only the next one to be entered, you'll want to look
    for COMP_WORDS in the bash documentation. (Check the number
    of entries and set COMPREPLY accordingly.)

    #!/bin/bash

    # Script that takes arguments , and echoes them.
    # If called with first argument "complete", it will set up
    # bash completion so that the command foo prints "path host port"
    # as possible completions.

    # To use this: name the file foo, and do:
    # % . foo complete
    # % ./foo

    if test "$1" != complete; then
    for i; do echo $i; done
    exit 0
    fi


    _foo() {
    COMPREPLY=('path host port')
    }

    complete -F _foo foo


  7. Re: How can i list my arguments while pressing tab?

    On Nov 4, 7:42 pm, "Chris F.A. Johnson" wrote:
    > On 2007-11-03, lak wrote:
    >
    > > Actually i wrote a bash script which accepts 5 positional parameter
    > > one at a time.

    >
    > The positional parameters are all on the command line
    > simultaneously. Do you mean "uses them one at a time"?
    >
    > > My requirement is, if the user press tab then i have to display the
    > > arguments.
    > > How can i do this?

    >
    > read -sn1
    > case $REPLY in
    > $'\t') printf "%s\n" "$@" ;;
    > esac
    >
    > --
    > Chris F.A. Johnson, author |
    > Shell Scripting Recipes: | My code in this post, if any,
    > A Problem-Solution Approach | is released under the
    > 2005, Apress | GNU General Public Licence


    I've just looked at the manual, I didn't know for those options.
    Thanks.
    Sorry lak, it was my mistake.

    Darko


+ Reply to Thread