mirror of
https://github.com/ksherlock/mpw-shell.git
synced 2024-12-28 09:29:57 +00:00
builtin_which -- also check builtin commands.
This commit is contained in:
parent
9b577bdbb1
commit
2fdca6ea9d
35
builtins.cpp
35
builtins.cpp
@ -33,12 +33,11 @@ namespace fs = filesystem;
|
||||
|
||||
namespace {
|
||||
|
||||
/*
|
||||
std::string &lowercase(std::string &s) {
|
||||
std::transform(s.begin(), s.end(), s.begin(), [](char c){ return std::tolower(c); });
|
||||
return s;
|
||||
}
|
||||
*/
|
||||
|
||||
// doesn't handle flag arguments but builtins don't have arguments.
|
||||
|
||||
template<class FX>
|
||||
@ -813,6 +812,38 @@ int builtin_which(Environment &env, const std::vector<std::string> &tokens, cons
|
||||
|
||||
}
|
||||
|
||||
// check builtins...
|
||||
if (!found || a) {
|
||||
|
||||
static const char *builtins[] = {
|
||||
"aboutbox",
|
||||
"alias",
|
||||
"catenate",
|
||||
"directory",
|
||||
"echo",
|
||||
"exists",
|
||||
"export",
|
||||
"parameters",
|
||||
"quote",
|
||||
"set",
|
||||
"shift",
|
||||
"unalias",
|
||||
"unexport",
|
||||
"unset",
|
||||
"version",
|
||||
"which",
|
||||
};
|
||||
|
||||
lowercase(target);
|
||||
|
||||
auto iter = std::find(std::begin(builtins), std::end(builtins), target);
|
||||
if (iter != std::end(builtins)) {
|
||||
fprintf(stdout, "%s\n", *iter);
|
||||
found = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (found) return 0;
|
||||
|
||||
// also check built-ins?
|
||||
|
Loading…
Reference in New Issue
Block a user