mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-10 07:04:29 +00:00
Add status current-commandline
Makes it possible to retrieve the currently executing command line as opposed to the currently executing command (`status current-command`). Closes #8905.
This commit is contained in:
parent
e01eb2e615
commit
6ac18defd2
5 changed files with 19 additions and 0 deletions
|
@ -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 <source>`, then this will return ``-``.
|
||||
|
||||
|
|
|
@ -113,6 +113,8 @@ maybe_t<int> 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);
|
||||
|
||||
|
|
|
@ -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_cmd_t> 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<int> 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"));
|
||||
|
|
|
@ -246,6 +246,7 @@ struct eval_res_t {
|
|||
|
||||
enum class parser_status_var_t : uint8_t {
|
||||
current_command,
|
||||
current_commandline,
|
||||
count_,
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue