I would like to split $argv into two variables. One with opts and one with everything else.
function filter_opts set -l filtered_opts set -l new_argv for opt in $argv if string match -r -- '-.*' $opt set -a filtered_opts $opt else set -a new_argv $opt end end set -g argv $new_argv echo $filtered_optsendfunction test_filter set -g argv $argv echo $argv set -l opts (filter_opts $argv) echo $opts echo $argv # prog1 $opts $argv # prog2 $argvend
But the output has the filtered opts duplicated and $argv isn't modified... :-(
$ test_filter Twilight Zone --test -tTwilight Zone --test -t--test -t --test -tTwilight Zone --test -t
Ideally the output would look like this:
$ test_filter Twilight Zone --test -tTwilight Zone --test -t--test -tTwilight Zone