mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
whence -v/-a: report path to autoloadable functions
Since at least 1999, whence -v on pdksh (and its successor mksh)
reports the path where an autoloadable function may be found:
$ mkdir ~/fun; FPATH=~/fun
$ echo 'myfn() { echo hi; }' >~/fun/myfn
$ whence -v myfn
myfn is a undefined (autoload from /home/user/fun/myfn) function
Whereas ksh93 only reports, rather uselessly:
myfn is an undefined function
As of this commit, whence -v/-a on ksh 93u+m does the same as
pdksh, but with correct grammar:
myfn is an undefined function (autoload from /home/user/fun/myfn)
This may be a small violation of my own "no new features" policy
for 93u+m, but I couldn't resist. This omission has been annoying
me, and it's just embarrassing to lack a pdksh feature :)
src/cmd/ksh93/include/path.h,
src/cmd/ksh93/data/msg.c:
- Add e_autoloadfrom[] = " (autoload from %s)" message.
src/cmd/ksh93/bltins/whence.c: whence():
- Report the path (if any) when reporting an undefined function.
This needs to be done in two places:
1. When a function has been explicitly marked undefined with
'autoload', we need to do a quick path_search() loop to find
the path. (These undefined functions take precedence over
regular commands, so are reported first.)
2. When a function is not explicitly autoloaded but merely
available in $FPATH, that path search was already done, so all
we need to do is report it. (These are reported last.)
Note that the output remains as on 93u+ if no function definition
file is found on $FPATH. This is also like pdksh/mksh.
src/cmd/ksh93/data/builtins.c:
- Bump 'whence' version date. The inline docs never detailed very
exactly what 'whence -v' reports, so no need for further edits.
src/cmd/ksh93/tests/path.sh:
- Regress-test the new whence behaviour plus actual autoloading,
including the command override behaviour of autoloaded functions.
This commit is contained in:
parent
cefe087d23
commit
3050bf28bc
6 changed files with 64 additions and 11 deletions
|
|
@ -1988,7 +1988,7 @@ _JOB_
|
|||
;
|
||||
|
||||
const char sh_optwhence[] =
|
||||
"[-1c?\n@(#)$Id: whence (AT&T Research/ksh93) 2020-07-20 $\n]"
|
||||
"[-1c?\n@(#)$Id: whence (AT&T Research/ksh93) 2020-09-25 $\n]"
|
||||
USAGE_LICENSE
|
||||
"[+NAME?whence, type - locate a command and describe its type]"
|
||||
"[+DESCRIPTION?Without \b-v\b, \bwhence\b writes on standard output an "
|
||||
|
|
|
|||
|
|
@ -141,6 +141,7 @@ const char is_alias[] = "%s is an alias for ";
|
|||
const char is_talias[] = "is a tracked alias for";
|
||||
const char is_function[] = " is a function";
|
||||
const char is_ufunction[] = " is an undefined function";
|
||||
const char e_autoloadfrom[] = " (autoload from %s)";
|
||||
#ifdef JOBS
|
||||
# ifdef SIGTSTP
|
||||
const char e_newtty[] = "Switching to new tty driver...";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue