Created
September 3, 2025 18:19
-
-
Save sampersand/a4218a05f4e585c14390b41426bb46c2 to your computer and use it in GitHub Desktop.
How can you do mutually exclusive values in zparseopts?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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