mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 20:33:08 +00:00
status returns the function name when called with -u parameter
Fixes #1743
This commit is contained in:
parent
2565c5c15b
commit
980af4aa5b
6 changed files with 33 additions and 0 deletions
|
@ -11,6 +11,7 @@ status is-no-job-control
|
||||||
status is-full-job-control
|
status is-full-job-control
|
||||||
status is-interactive-job-control
|
status is-interactive-job-control
|
||||||
status current-filename
|
status current-filename
|
||||||
|
status current-function
|
||||||
status current-line-number
|
status current-line-number
|
||||||
status print-stack-trace
|
status print-stack-trace
|
||||||
status job-control CONTROL-TYPE
|
status job-control CONTROL-TYPE
|
||||||
|
@ -38,6 +39,8 @@ The following operations (sub-commands) are available:
|
||||||
|
|
||||||
- `current-filename` prints the filename of the currently running script. Also `-f` or `--current-filename`.
|
- `current-filename` prints the filename of the currently running script. Also `-f` or `--current-filename`.
|
||||||
|
|
||||||
|
- `current-function` prints the name of the currently called function if able, when missing displays "Not a function". Also `-u` or `--current-function`.
|
||||||
|
|
||||||
- `current-line-number` prints the line number of the currently running script. Also `-n` or `--current-line-number`.
|
- `current-line-number` prints the line number of the currently running script. Also `-n` or `--current-line-number`.
|
||||||
|
|
||||||
- `job-control CONTROL-TYPE` sets the job control type, which can be `none`, `full`, or `interactive`. Also `-j CONTROL-TYPE` or `--job-control=CONTROL-TYPE`.
|
- `job-control CONTROL-TYPE` sets the job control type, which can be `none`, `full`, or `interactive`. Also `-j CONTROL-TYPE` or `--job-control=CONTROL-TYPE`.
|
||||||
|
|
|
@ -2368,6 +2368,7 @@ enum status_cmd_t {
|
||||||
STATUS_IS_INTERACTIVE_JOB_CTRL,
|
STATUS_IS_INTERACTIVE_JOB_CTRL,
|
||||||
STATUS_IS_NO_JOB_CTRL,
|
STATUS_IS_NO_JOB_CTRL,
|
||||||
STATUS_CURRENT_FILENAME,
|
STATUS_CURRENT_FILENAME,
|
||||||
|
STATUS_CURRENT_FUNCTION,
|
||||||
STATUS_CURRENT_LINE_NUMBER,
|
STATUS_CURRENT_LINE_NUMBER,
|
||||||
STATUS_SET_JOB_CONTROL,
|
STATUS_SET_JOB_CONTROL,
|
||||||
STATUS_PRINT_STACK_TRACE,
|
STATUS_PRINT_STACK_TRACE,
|
||||||
|
@ -2376,6 +2377,7 @@ enum status_cmd_t {
|
||||||
// Must be sorted by string, not enum or random.
|
// Must be sorted by string, not enum or random.
|
||||||
const enum_map<status_cmd_t> status_enum_map[] = {
|
const enum_map<status_cmd_t> status_enum_map[] = {
|
||||||
{STATUS_CURRENT_FILENAME, L"current-filename"},
|
{STATUS_CURRENT_FILENAME, L"current-filename"},
|
||||||
|
{STATUS_CURRENT_FUNCTION, L"current-function"},
|
||||||
{STATUS_CURRENT_LINE_NUMBER, L"current-line-number"},
|
{STATUS_CURRENT_LINE_NUMBER, L"current-line-number"},
|
||||||
{STATUS_IS_BLOCK, L"is-block"},
|
{STATUS_IS_BLOCK, L"is-block"},
|
||||||
{STATUS_IS_COMMAND_SUB, L"is-command-substitution"},
|
{STATUS_IS_COMMAND_SUB, L"is-command-substitution"},
|
||||||
|
@ -2608,6 +2610,14 @@ static int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **arg
|
||||||
streams.out.append_format(L"%ls\n", fn);
|
streams.out.append_format(L"%ls\n", fn);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case STATUS_CURRENT_FUNCTION: {
|
||||||
|
CHECK_FOR_UNEXPECTED_STATUS_ARGS(status_cmd)
|
||||||
|
const wchar_t *fn = parser.get_function_name();
|
||||||
|
|
||||||
|
if (!fn) fn = _(L"Not a function");
|
||||||
|
streams.out.append_format(L"%ls\n", fn);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case STATUS_CURRENT_LINE_NUMBER: {
|
case STATUS_CURRENT_LINE_NUMBER: {
|
||||||
CHECK_FOR_UNEXPECTED_STATUS_ARGS(status_cmd)
|
CHECK_FOR_UNEXPECTED_STATUS_ARGS(status_cmd)
|
||||||
streams.out.append_format(L"%d\n", parser.get_lineno());
|
streams.out.append_format(L"%d\n", parser.get_lineno());
|
||||||
|
|
|
@ -440,6 +440,10 @@ const wchar_t *parser_t::is_function() const {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const wchar_t *parser_t::get_function_name() {
|
||||||
|
return this->is_function();
|
||||||
|
}
|
||||||
|
|
||||||
int parser_t::get_lineno() const {
|
int parser_t::get_lineno() const {
|
||||||
int lineno = -1;
|
int lineno = -1;
|
||||||
if (!execution_contexts.empty()) {
|
if (!execution_contexts.empty()) {
|
||||||
|
|
|
@ -306,6 +306,9 @@ class parser_t {
|
||||||
/// Return a description of the given blocktype.
|
/// Return a description of the given blocktype.
|
||||||
const wchar_t *get_block_desc(int block) const;
|
const wchar_t *get_block_desc(int block) const;
|
||||||
|
|
||||||
|
/// Return the current function name.
|
||||||
|
const wchar_t *get_function_name();
|
||||||
|
|
||||||
/// Removes a job.
|
/// Removes a job.
|
||||||
bool job_remove(job_t *job);
|
bool job_remove(job_t *job);
|
||||||
|
|
||||||
|
|
|
@ -39,3 +39,13 @@ status --job-control=1none
|
||||||
|
|
||||||
# Now set it to a valid mode.
|
# Now set it to a valid mode.
|
||||||
status job-control none
|
status job-control none
|
||||||
|
|
||||||
|
# Check status -u outside functions
|
||||||
|
status current-function
|
||||||
|
|
||||||
|
function test_function
|
||||||
|
status current-function
|
||||||
|
end
|
||||||
|
|
||||||
|
test_function
|
||||||
|
eval test_function
|
|
@ -0,0 +1,3 @@
|
||||||
|
Not a function
|
||||||
|
test_function
|
||||||
|
test_function
|
Loading…
Reference in a new issue