diff --git a/doc_src/cmds/status.rst b/doc_src/cmds/status.rst index baf3a5d92..825dc960b 100644 --- a/doc_src/cmds/status.rst +++ b/doc_src/cmds/status.rst @@ -18,6 +18,7 @@ Synopsis status is-full-job-control status is-interactive-job-control status current-command + status current-commandline status filename status basename status dirname @@ -63,6 +64,9 @@ The following operations (subcommands) are available: **current-command** Prints the name of the currently-running function or command, like the deprecated :envvar:`_` variable. +**current-commandline** + Prints the entirety of the currently-running commandline, inclusive of all jobs and operators. + **filename**, **current-filename**, **-f** or **--current-filename** Prints the filename of the currently-running script. If the current script was called via a symlink, this will return the symlink. If the current script was received by piping into :doc:`source `, then this will return ``-``. diff --git a/src/builtins/fg.cpp b/src/builtins/fg.cpp index 93397dc80..3ca0fe52f 100644 --- a/src/builtins/fg.cpp +++ b/src/builtins/fg.cpp @@ -113,6 +113,8 @@ maybe_t builtin_fg(parser_t &parser, io_streams_t &streams, const wchar_t * parser.set_status_var(parser_status_var_t::current_command, ft); // Also provide a value for the deprecated fish 2.0 $_ variable parser.set_var_and_fire(L"_", ENV_EXPORT, std::move(ft)); + // Provide value for `status current-commandline` + parser.set_status_var(parser_status_var_t::current_commandline, job->command()); } reader_write_title(job->command(), parser); diff --git a/src/builtins/status.cpp b/src/builtins/status.cpp index 4058131be..881406878 100644 --- a/src/builtins/status.cpp +++ b/src/builtins/status.cpp @@ -46,6 +46,7 @@ enum status_cmd_t { STATUS_SET_JOB_CONTROL, STATUS_STACK_TRACE, STATUS_TEST_FEATURE, + STATUS_CURRENT_COMMANDLINE, STATUS_UNDEF }; @@ -54,6 +55,7 @@ const enum_map status_enum_map[] = { {STATUS_BASENAME, L"basename"}, {STATUS_BASENAME, L"current-basename"}, {STATUS_CURRENT_CMD, L"current-command"}, + {STATUS_CURRENT_COMMANDLINE, L"current-commandline"}, {STATUS_DIRNAME, L"current-dirname"}, {STATUS_FILENAME, L"current-filename"}, {STATUS_FUNCTION, L"current-function"}, @@ -459,6 +461,13 @@ maybe_t builtin_status(parser_t &parser, io_streams_t &streams, const wchar } break; } + case STATUS_CURRENT_COMMANDLINE: { + CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd) + const auto &var = parser.get_status_var(parser_status_var_t::current_commandline); + streams.out.append(var); + streams.out.push_back(L'\n'); + break; + } case STATUS_FISH_PATH: { CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd); auto path = str2wcstring(get_executable_path("fish")); diff --git a/src/parser.h b/src/parser.h index 82a66cab3..51d235bb5 100644 --- a/src/parser.h +++ b/src/parser.h @@ -246,6 +246,7 @@ struct eval_res_t { enum class parser_status_var_t : uint8_t { current_command, + current_commandline, count_, }; diff --git a/src/reader.cpp b/src/reader.cpp index 521dbb0f9..2238182dc 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2633,6 +2633,7 @@ static eval_res_t reader_run_command(parser_t &parser, const wcstring &cmd) { // Provide values for `status current-command` and `status current-commandline` if (!ft.empty()) { parser.set_status_var(parser_status_var_t::current_command, ft); + parser.set_status_var(parser_status_var_t::current_commandline, cmd); // Also provide a value for the deprecated fish 2.0 $_ variable parser.vars().set_one(L"_", ENV_GLOBAL, ft); } @@ -2661,6 +2662,8 @@ static eval_res_t reader_run_command(parser_t &parser, const wcstring &cmd) { parser.set_status_var(parser_status_var_t::current_command, program_name); // Also provide a value for the deprecated fish 2.0 $_ variable parser.vars().set_one(L"_", ENV_GLOBAL, program_name); + // Provide value for `status current-commandline` + parser.set_status_var(parser_status_var_t::current_commandline, L""); if (have_proc_stat()) { proc_update_jiffies(parser);