FISH_OPT(1)
π FISH_OPT(1) β the fish-shell girlie's guide
okay so this is fish_opt from the fish-shell manual, and honestly? it's giving β¨ helper-function-that-helps-you-help-yourself β¨. stick with me bestie, we're gonna get through it together π«Ά
β¨ NAME β¨
fish_opt β creates an option specification for the argparse command π
πΈ SYNOPSIS πΈ
fish_opt [-s ALPHANUM] [-l LONG-NAME] [-ormd] [--long-only] [-v COMMAND OPTIONS ... ]
fish_opt --help
π¦ DESCRIPTION π¦
so basically, this command is your little building-block bestie: it produces option specifications that are suitable for use with the argparse command. and like β you absolutely can hand-write those option specifications yourself, nobody's stopping you, no cap. but you might prefer to use this command for the clarity it provides. and we love clarity π
here are all the argparse options it gives you, one by one, no skips:
π the options π
-sor--shortALPHANUM β takes a single letter or number, and that becomes the short flag of the option you're defining. you gotta give either this one or the--longoption β one of them, periodt. π-lor--longLONG-NAME β takes a string, and that string becomes the long flag of the option you're defining. this one's optional and has no default. heads up though: if no long flag is defined, then only the short flag will be allowed when parsing arguments with this option specification. π--long-onlyβ deprecated, bestie, so maybe don't. it makes the option you're defining only allow the long flag name to be used, even if the short flag is defined (like, i.e., even when--shortis specified). π-oor--optional-valβ the option you're defining can take a value, but it's optional rather than required. if the option shows up more than once while parsing arguments, only the last value seen is saved. what that means: the resulting flag variable created byargparsewill have zero elements if no value was given with the option, else it'll have exactly one element. cute, tidy, iconic. β¨-ror--required-valβ the option you're defining requires a value. if it's seen more than once while parsing arguments, only the last value seen is saved. so the resulting flag variable created byargparsewill have exactly one element. main character energy, always exactly one π₯-mor--multiple-valsβ the value of each instance of the option gets accumulated. if--optional-valis provided, the value is optional and an empty string is stored when no value is provided. otherwise, the--requiured-valoption is implied and every instance of the option requires a value. (yes that's spelled--requiured-valin here, we don't make the rules π€·). what that means: the resulting flag variable created byargparsewill have one element for each instance of this option in the arguments β even for the instances that didn't provide a value. the way it just hoards them all ππ-dor--deleteβ the option and any values get deleted from the$argv_optsvariables set byargparse. and like the other options, it also gets deleted from$argv. poof, gone, bye queen π-vor--validateCOMMAND OPTION... β this one must be the last one, and it requires one of-o,-r, or-m. all the remaining arguments get interpreted as a fish script to run, to validate the value of the argument β see theargparsedocumentation for more details. > β οΈ note that the interpretation of COMMAND OPTION... is similar toeval, so you may need to quote or escape special characters twice if you want them to be interpreted literally when the validate script is run. double the escaping, double the fun π§-hor--helpβ displays help about using this command. the classic, the legend, the "help me help you" π«Ά
π EXAMPLES π
β define a single option specification for the boolean help flag:
set -l options (fish_opt -s h -l help)
argparse $options -- $argv
β same as above but with a second flag that requires a value:
set -l options (fish_opt -s h -l help)
set options $options (fish_opt -s m -l max -r)
argparse $options -- $argv
β same as above but the value of the second flag cannot be the empty string:
set -l options (fish_opt -s h -l help)
set options $options (fish_opt -s m -l max -rv test \$_flag_value != "''")
argparse $options -- $argv
β same as above but with a third flag that can be given multiple times, saving the value of each instance seen β and only a long flag name (--token) is defined:
set -l options (fish_opt --short=h --long=help)
set options $options (fish_opt --short=m --long=max --required-val --validate test \$_flag_value != "''")
set options $options (fish_opt --long=token --multiple-vals)
argparse $options -- $argv
look at that little stack of specs go ππ ate and left no crumbs.
π COPYRIGHT π
fish-shell developers β that's the whole copyright section, short and sweet, respect the devs β¨
π ok that's the page!! so real of you for reading all the way down here, ily.
and a lil cute sign-off to wrap it up: this page is from the fish-shell manual, version 4.9, dated Sep 08, 2026 β write that down bestie, iykyk πππΈ
π¦ where this page comes from
- arch rolling: fish 4.9.3-1 Β· GPL-2.0-only AND BSD-3-Clause AND ISC AND MIT AND PSF-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms