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 πŸŽ€

  • -s or --short ALPHANUM β€” 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 --long option β€” one of them, periodt. πŸ’…
  • -l or --long LONG-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 --short is specified). πŸ’€
  • -o or --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 by argparse will have zero elements if no value was given with the option, else it'll have exactly one element. cute, tidy, iconic. ✨
  • -r or --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 by argparse will have exactly one element. main character energy, always exactly one πŸ”₯
  • -m or --multiple-vals β€” the value of each instance of the option gets accumulated. if --optional-val is provided, the value is optional and an empty string is stored when no value is provided. otherwise, the --requiured-val option is implied and every instance of the option requires a value. (yes that's spelled --requiured-val in here, we don't make the rules 🀷). what that means: the resulting flag variable created by argparse will 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 πŸ˜­πŸ’–
  • -d or --delete β€” the option and any values get deleted from the $argv_opts variables set by argparse. and like the other options, it also gets deleted from $argv. poof, gone, bye queen πŸ‘‹
  • -v or --validate COMMAND 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 the argparse documentation for more details. > ⚠️ note that the interpretation of COMMAND OPTION... is similar to eval, 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 🧚
  • -h or --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.


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