Read arguments with fish -c

This reads any additional positional arguments given to `fish -c` into
$argv.

We don't handle the first argument specially (as `$0`) as that's confusing and
doesn't seem very useful.

Fixes #2314.
This commit is contained in:
Fabian Homborg
2020-09-26 14:45:51 +02:00
parent 396d7e105f
commit fa0c9f90f8
3 changed files with 15 additions and 2 deletions

View File

@@ -489,6 +489,14 @@ int main(int argc, char **argv) {
fish_xdm_login_hack_hack_hack_hack(&opts.batch_cmds, argc - my_optind,
argv + my_optind);
}
// Pass additional args as $argv.
// Note that we *don't* support setting argv[0]/$0, unlike e.g. bash.
wcstring_list_t list;
for (char **ptr = argv + my_optind; *ptr; ptr++) {
list.push_back(str2wcstring(*ptr));
}
parser.vars().set(L"argv", ENV_DEFAULT, std::move(list));
res = run_command_list(parser, &opts.batch_cmds, {});
parser.libdata().exit_current_script = false;
} else if (my_optind == argc) {