Extend type --path to print path to script defining named function

Expands the utility of `type -p foo` by allowing it to print the path to
the script that defines `foo` when `foo` is a valid function that was
sourced from a path on disk (rather than interactively defined).

This does not change the behavior of `type -P`/`type --force-path`,
which should have already been used if the desire was to resolve the
path to an executable file (otherwise the output would have been blank
if a function was shadowing an executable file of the same namea), so no
backwards compatibility issues are expected.
This commit is contained in:
Mahmoud Al-Qudsi 2019-01-16 17:29:43 -06:00
parent 8079345207
commit d651cdacbe

View file

@ -56,6 +56,15 @@ function type --description 'Print the type of a command'
end end
case type case type
echo (_ 'function') echo (_ 'function')
case path
set -l func_path (functions --details $i)
switch $func_path
case "n/a"
case "stdin"
break;
case "*"
echo $func_path
end
end end
if test $multi != yes if test $multi != yes
continue continue