mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-06 10:08:47 +00:00
Skip variable assignments in status current command
Fixes #6635
(cherry picked from commit aa0e16b1a5
)
This commit is contained in:
parent
26949fa865
commit
676a97cf0b
5 changed files with 23 additions and 2 deletions
|
@ -98,7 +98,7 @@ int builtin_fg(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
std::fwprintf(stderr, FG_MSG, job->job_id(), job->command_wcstr());
|
std::fwprintf(stderr, FG_MSG, job->job_id(), job->command_wcstr());
|
||||||
}
|
}
|
||||||
|
|
||||||
const wcstring ft = tok_first(job->command());
|
const wcstring ft = tok_command(job->command());
|
||||||
// For compatibility with fish 2.0's $_, now replaced with `status current-command`
|
// For compatibility with fish 2.0's $_, now replaced with `status current-command`
|
||||||
if (!ft.empty()) parser.vars().set_one(L"_", ENV_EXPORT, ft);
|
if (!ft.empty()) parser.vars().set_one(L"_", ENV_EXPORT, ft);
|
||||||
reader_write_title(job->command(), parser);
|
reader_write_title(job->command(), parser);
|
||||||
|
|
|
@ -1943,7 +1943,7 @@ void set_env_cmd_duration(struct timeval *after, struct timeval *before, env_sta
|
||||||
void reader_run_command(parser_t &parser, const wcstring &cmd) {
|
void reader_run_command(parser_t &parser, const wcstring &cmd) {
|
||||||
struct timeval time_before, time_after;
|
struct timeval time_before, time_after;
|
||||||
|
|
||||||
wcstring ft = tok_first(cmd);
|
wcstring ft = tok_command(cmd);
|
||||||
|
|
||||||
// For compatibility with fish 2.0's $_, now replaced with `status current-command`
|
// For compatibility with fish 2.0's $_, now replaced with `status current-command`
|
||||||
if (!ft.empty()) parser.vars().set_one(L"_", ENV_GLOBAL, ft);
|
if (!ft.empty()) parser.vars().set_one(L"_", ENV_GLOBAL, ft);
|
||||||
|
|
|
@ -663,6 +663,21 @@ wcstring tok_first(const wcstring &str) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wcstring tok_command(const wcstring &str) {
|
||||||
|
tokenizer_t t(str.c_str(), 0);
|
||||||
|
while (auto token = t.next()) {
|
||||||
|
if (token->type != token_type_t::string) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
wcstring text = t.text_of(*token);
|
||||||
|
if (variable_assignment_equals_pos(text)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
bool move_word_state_machine_t::consume_char_punctuation(wchar_t c) {
|
bool move_word_state_machine_t::consume_char_punctuation(wchar_t c) {
|
||||||
enum { s_always_one = 0, s_rest, s_whitespace_rest, s_whitespace, s_alphanumeric, s_end };
|
enum { s_always_one = 0, s_rest, s_whitespace_rest, s_whitespace, s_alphanumeric, s_end };
|
||||||
|
|
||||||
|
|
|
@ -144,6 +144,9 @@ class tokenizer_t {
|
||||||
/// returns the empty string.
|
/// returns the empty string.
|
||||||
wcstring tok_first(const wcstring &str);
|
wcstring tok_first(const wcstring &str);
|
||||||
|
|
||||||
|
/// Like to tok_first, but skip variable assignments like A=B.
|
||||||
|
wcstring tok_command(const wcstring &str);
|
||||||
|
|
||||||
/// Struct wrapping up a parsed pipe or redirection.
|
/// Struct wrapping up a parsed pipe or redirection.
|
||||||
struct pipe_or_redir_t {
|
struct pipe_or_redir_t {
|
||||||
// The redirected fd, or -1 on overflow.
|
// The redirected fd, or -1 on overflow.
|
||||||
|
|
|
@ -37,6 +37,9 @@ status job-control none
|
||||||
# Check status -u outside functions
|
# Check status -u outside functions
|
||||||
status current-function
|
status current-function
|
||||||
|
|
||||||
|
a=b status current-command
|
||||||
|
#CHECK: status
|
||||||
|
|
||||||
function test_function
|
function test_function
|
||||||
status current-function
|
status current-function
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue