Skip to content

Instantly share code, notes, and snippets.

@sampersand
Created September 3, 2025 18:19
Show Gist options
  • Select an option

  • Save sampersand/a4218a05f4e585c14390b41426bb46c2 to your computer and use it in GitHub Desktop.

Select an option

Save sampersand/a4218a05f4e585c14390b41426bb46c2 to your computer and use it in GitHub Desktop.
How can you do mutually exclusive values in zparseopts?
#!/bin/zsh
usage () cat <<EOS
usage: ${ZSH_SCRIPT:t:s/-/ /} [-c | -m | -p | -bBRANCH] [file] [start[-end]]
options:
-c use the current branch
-m use the master branch [default]
-p get a permalink
-bBRANCH use BRANCH
Prints out a link to the repo, optoinally to 'file' (or a range of lines in it)
EOS
set -- -c -bfoo -p -bbar # Test data
# Parse options
zparseopts -D -- \
{c,m,p,b:}=opts \
h=help
# :-( It's not `-c -p -b bar`
print -- $opts #=> -c -b bar -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment