Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to get the current function name #1743

Closed
xdudi opened this issue Oct 6, 2014 · 4 comments
Closed

Add a way to get the current function name #1743

xdudi opened this issue Oct 6, 2014 · 4 comments
Labels
enhancement good first issue release notes Something that is or should be mentioned in the release notes
Milestone

Comments

@xdudi
Copy link

xdudi commented Oct 6, 2014

~> function test_func
       echo $_ $argv
   end
~> test_func (seq 10)
test_func 1 2 3 4 5 6 7 8 9 10
~> eval test_func (seq 10)
eval 1 2 3 4 5 6 7 8 9 10             # should be test_func
~> 

I would suggest to add %this as equivalent of $_ for return function/script name.

@lilyball
Copy link
Contributor

What makes you say this is the wrong value?

$_ is set by the interactive reader. You'll notice that echo 'echo _="$_"' | fish or fish -c 'echo _="$_"' both print _=, because the $_ variable isn't even set there. Because there's no interactive reader.

Which is to say, when you run the line eval test_func (seq 10), the interactive reader assigns $_ = "eval", and then the job run by eval itself, by virtue of not being an interactive read, doesn't touch $_.

Which is to say, this is behaving correctly. $_ contains the name of the command typed by the user.

And %this would not be appropriate, as % is the process expansion token.

If you want a way to get the name of the currently-executing function, then the best bet is to teach status how to do that. But why do you even need this? Surely the test_func function already knows that its name is test_func.

@ridiculousfish ridiculousfish added this to the fish-tank milestone Nov 1, 2014
@faho
Copy link
Member

faho commented Sep 2, 2015

No info in >6 months. Closing.

@ghost
Copy link

ghost commented Oct 18, 2015

Any chances we can revive this?

See #2492

But why do you even need this? Surely the test_func function already knows that its name is test_func.

Because it is a good practice to not repeat oneself and I may be looking for a way to automate something like displaying a usage message, etc.

then the best bet is to teach status how to do that.

Any chance to teach a variable instead? 😄

@faho faho reopened this Oct 18, 2015
@faho faho changed the title "$_" has wrong value Add a way to get the current function name May 21, 2016
@krader1961 krader1961 modified the milestone: fish-tank Nov 17, 2016
@krader1961
Copy link
Contributor

Note that we already have status print-stack-trace (which includes the name of the current function) and status current-filename. Adding status current-funcname is not unreasonable and probably straightforward.

@krader1961 krader1961 added this to the fish-future milestone Mar 18, 2017
@zanchey zanchey modified the milestones: 2.6.0, fish-future Apr 27, 2017
@faho faho added the release notes Something that is or should be mentioned in the release notes label May 5, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement good first issue release notes Something that is or should be mentioned in the release notes
Projects
None yet
Development

No branches or pull requests

6 participants