diff --git a/exec.cpp b/exec.cpp index 599158865..10baa76bf 100644 --- a/exec.cpp +++ b/exec.cpp @@ -525,9 +525,6 @@ static void internal_exec_helper(parser_t &parser, return; } - int is_block_old=is_block; - is_block=1; - signal_unblock(); if (node_offset == NODE_OFFSET_INVALID) @@ -544,7 +541,6 @@ static void internal_exec_helper(parser_t &parser, morphed_chain.clear(); io_cleanup_fds(opened_fds); job_reap(0); - is_block=is_block_old; } /* Returns whether we can use posix spawn for a given process in a given job. diff --git a/parser.cpp b/parser.cpp index 3740f1fbe..be7e494af 100644 --- a/parser.cpp +++ b/parser.cpp @@ -278,6 +278,12 @@ void parser_t::push_block(block_t *new_current) this->block_stack.push_back(new_current); + // Types TOP and SUBST are not considered blocks for the purposes of `status -b` + if (type != TOP && type != SUBST) + { + is_block = 1; + } + if ((new_current->type() != FUNCTION_DEF) && (new_current->type() != FAKE) && (new_current->type() != TOP)) @@ -305,6 +311,19 @@ void parser_t::pop_block() env_pop(); delete old; + + // Figure out if `status -b` should consider us to be in a block now + int new_is_block=0; + for (std::vector::const_iterator it = block_stack.begin(), end = block_stack.end(); it != end; ++it) + { + const enum block_type_t type = (*it)->type(); + if (type != TOP && type != SUBST) + { + new_is_block = 1; + break; + } + } + is_block = new_is_block; } void parser_t::pop_block(const block_t *expected) diff --git a/tests/status.in b/tests/status.in index 14dff2320..875f62f38 100644 --- a/tests/status.in +++ b/tests/status.in @@ -1,9 +1,17 @@ # vim: set filetype=fish: +status -b +or echo 'top level' + +begin + status -b +end +and echo 'block' + # Issue #1728 # Bad file redirection on a block causes `status --is-block` to return 0 forever. begin; end >/ # / is a directory, it can't be opened for writing status -b -and echo 'block' +and echo 'unexpected block' true diff --git a/tests/status.out b/tests/status.out index e69de29bb..a6546ffd0 100644 --- a/tests/status.out +++ b/tests/status.out @@ -0,0 +1,2 @@ +top level +block