mirror of
https://github.com/ksherlock/mpw-shell.git
synced 2024-06-01 08:41:32 +00:00
use filesystem::current_path for builtin_directoery
This commit is contained in:
parent
034321830f
commit
7d18720162
24
builtins.cpp
24
builtins.cpp
|
@ -375,25 +375,29 @@ int builtin_directory(Environment &env, const std::vector<std::string> &tokens,
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo -- if relative path does not exist, check {DirectoryPath}
|
// todo -- if relative path does not exist, check {DirectoryPath}
|
||||||
std::string path = ToolBox::MacToUnix(argv.front());
|
fs::path path = ToolBox::MacToUnix(argv.front());
|
||||||
int ok = chdir(path.c_str());
|
std::error_code ec;
|
||||||
if (ok < 0) {
|
current_path(path, ec);
|
||||||
|
if (ec) {
|
||||||
fputs("### Directory - Unable to set current directory.\n", stderr);
|
fputs("### Directory - Unable to set current directory.\n", stderr);
|
||||||
perror("chdir: ");
|
fprintf(stderr, "# %s\n", ec.message().c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// pwd
|
// pwd
|
||||||
char buffer[MAXPATHLEN];
|
std::error_code ec;
|
||||||
char *cp = getcwd(buffer, sizeof(buffer));
|
fs::path path = fs::current_path(ec);
|
||||||
if (!cp) {
|
if (ec) {
|
||||||
perror("getcwd: ");
|
|
||||||
|
fputs("### Directory - Unable to get current directory.\n", stderr);
|
||||||
|
fprintf(stderr, "# %s\n", ec.message().c_str());
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
// todo -- pathname translation?
|
// todo -- pathname translation?
|
||||||
|
|
||||||
std::string s = buffer;
|
std::string s = path;
|
||||||
if (!q) s = quote(std::move(s));
|
if (!q) s = quote(std::move(s));
|
||||||
fprintf(stdout, "%s\n", s.c_str());
|
fprintf(stdout, "%s\n", s.c_str());
|
||||||
}
|
}
|
||||||
|
@ -579,7 +583,7 @@ int builtin_which(Environment &env, const std::vector<std::string> &tokens, cons
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(; ss; ++ss) {
|
for(; ss; ++ss) {
|
||||||
if (p) fprintf(stderr, "checking %s\n", ss->c_str());
|
if (p) fprintf(stderr, "checking %s\n", ss->c_str());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user