Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8411971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:33:36+00:00 2026-06-10T00:33:36+00:00

I have a shell script it’s usage is: foo.sh <name> <type> <*.tar.gz> I want

  • 0

I have a shell script it’s usage is:

foo.sh <name> <type> <*.tar.gz>

I want to setup a complete on 3rd parameter only.
If I press on 1st parameter, just show the usage.

Could I use zsh’s zshcomp to do this job?

for example:

foo.sh <tab>  # display usage
foo.sh a b <tab> # show files match with *.tar.gz

Is there similar script which I could follow?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:33:37+00:00Added an answer on June 10, 2026 at 12:33 am

    Things to read.

    Here is a blog post discussing the Z-Shell Completion System.

    For a slightly more in-depth discussion, read this unix.stackexchange answer.

    And, as always, read the man pages!.

    Edit: Forgot to add: echo $fpath will show you the function path that zsh uses. On OSX, I have: /usr/local/share/zsh/4.3.17/functions, (location may vary for you), which contains all the ZSH completion functions. Have a look at _ssh, _ls, _tar etc – they’re all there, and they all have lots of nifty features you can learn from.


    Addressing the question: the direction you should go.

    What you’re asking is achievable, though. There are several steps.

    1. You need to write a z-shell completion function. It needs to be located on the fpath; the function-path that zsh uses for it’s completion system functions. (If it’s a small function, putting it into ~/.zshrc will also work, but isn’t recommended).

    2. You want completion on the 3rd parameter. To do that, your function would look something like the following:

      _arguments "3:<MENU>:<COMPLETION>"
      

      <MENU> is the menu description, which you’ll see if you’ve enabled the menu descriptions. (That’s done using zstyle; read the man pages, or the linked pages, for more information).
      <COMPLETION> is the things that you can complete with. For example, if you used:

      _arguments "3::(Foo Bar)"
      

      when you ran your script and pressed <TAB>, you’d have the option of either Foo or Bar.
      [NOTE: There is no <MENU> in that example. If you don’t want a menu descriptor, you can omit it as shown].

    3. You want completion on *.tar files. You can call _files to do that:

      _files -g \*.tar
      
    4. Show usage on first parameter: that’d be a completion with no arguments (ie, argument 1). I’m not sure why you’d want completion on only the third option but not the first two (typical usage descriptions), so I don’t know how to answer this. If your script is supposed to be used like this: script foo bar FILE.tar, wouldn’t you want to complete the foo and bar arguments as well?
      Perhaps a better solution would be displaying the usage when the script is run without parameters.

    Full script would look something like the following:

    
    #compdef myscript
    
    _arguments "3:tar files:_files -g \*.tar"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a shell script with a lot of echo statements. I want to
I have a shell script to automate the creation of separate tar files for
I have a shell script that outputs filenames (one per line). I want to
I have a shell script that I want to get the date and time
I have a shell script which I want to run without using the sh
I have a shell script that I want to set uid bit. I set
I have a shell script I use for deployments. Since I want to capture
I have some shell script as below, I want to run this process for
I have a shell script that runs as root. I want the script to
I have a shell script like this. line=$@ # get the complete first line

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.