serhii.net

In the middle of the desert you can say anything you want

07 Aug 2025

fish arguments and functions

Below:

  • h/help is a flag
  • o/output-dir gets+requires a value
  • or return fails on unknown -a/--args
  • If found, the value is removed from $argv and put into _flag_argname
  • set -query (tests if var is set) -local
argparse h/help o/output-dir= -- $argv 
or return

if set -ql _flag_help
	echo "Usage: script.fish [-o/--output-dir <dir>] <input_files_or_directory>"
	echo "Example: script.fish --output-dir /path/to/output file1.png directory_with_pngs/ dir/*.png"
	exit 0
end

if set -ql _flag_output_dir
	set output_dir $_flag_output_dir
end


for arg in $argv
	# do something with file $arg
end
Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus