'How to get the program name in a fish shell script?

In bash, as in ruby, the program name is given by $0. What is it in fish? I can do the following if I have to:

set PROGRAM (ps --no-header -o args -p %self | egrep -o '\S+')[2]

But I'm sure the program name must be already available somewhere. I could also set the program name in variable at the stub of each program, but that has maintenance problems.



Solution 1:[1]

For fish use $_ for program name.

Solution 2:[2]

fish 3.x

status current-command

See Deprecations section of the 3.0 documentation.

fish 2.x

Use $_ for program name.

See Programmable title section of the 2.0 documentation.

Solution 3:[3]

In the docs you can see that as of version 3.4.1 you can simply use

echo (status basename)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jaypal singh
Solution 2 Édouard Lopez
Solution 3 Phil