Skip to content

Commit

Permalink
Exit if --no-execute is enabled don't interactively read from the ter…
Browse files Browse the repository at this point in the history
…minal

Don't go into implicit interactive mode without ever executing
anything - not even `exit` or reacting to ctrl-d. That just renders
the shell useless and unquittable.
  • Loading branch information
faho committed Jan 1, 2021
1 parent eb43fc8 commit cf8219e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/fish.cpp
Expand Up @@ -503,6 +503,10 @@ int main(int argc, char **argv) {
parser.libdata().exit_current_script = false;
} else if (my_optind == argc) {
// Implicitly interactive mode.
if (opts.no_exec && isatty(STDIN_FILENO)) {
FLOGF(error, L"no-execute mode enabled and no script given. Exiting");
return EXIT_FAILURE; // above line should always exit
}
res = reader_read(parser, STDIN_FILENO, {});
} else {
const char *file = *(argv + (my_optind++));
Expand Down
3 changes: 3 additions & 0 deletions tests/checks/invocation.fish
Expand Up @@ -53,3 +53,6 @@ $fish -c 'string escape y$argv' -c 'string escape x$argv' 1 2 3
# CHECK: x1
# CHECK: x2
# CHECK: x3

# Should just do nothing.
$fish --no-execute
3 changes: 3 additions & 0 deletions tests/pexpects/generic.py
Expand Up @@ -51,5 +51,8 @@
sendline("echo hoge >| \n cat")
expect_prompt("hoge")

sendline("$fish --no-execute 2>&1")
expect_prompt("error: no-execute mode enabled and no script given. Exiting")

sendline("source; or echo failed")
expect_prompt("failed")

0 comments on commit cf8219e

Please sign in to comment.