Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0f9c6a234
|
||
|
|
4b0f3b8fb7
|
||
|
|
24914028c0
|
||
|
|
0d126021d0
|
@@ -14,24 +14,42 @@ void Function::register_extented(BEd &ctx) {
|
||||
.default_address = "",
|
||||
.accept_zero = false,
|
||||
.pre_text_mode = nullptr,
|
||||
.handle = [](BEd &ctx, const buffer::Address &, vase::Shard *, const Argument &arg_, std::vector<buffer::Line> *) {
|
||||
.handle = [](BEd &, const buffer::Address &, vase::Shard *, const Argument &arg_, std::vector<buffer::Line> *) {
|
||||
auto path = std::get<std::string>(arg_);
|
||||
const auto first = path.find_first_not_of(" \t");
|
||||
const auto last = path.find_last_not_of(" \t");
|
||||
path = path.substr(first, last - first + 1);
|
||||
if (first == std::string::npos)
|
||||
path.clear();
|
||||
else
|
||||
path = path.substr(first, last - first + 1);
|
||||
if (path.empty())
|
||||
path = getenv("HOME");
|
||||
if (path == "~")
|
||||
path = std::getenv("HOME");
|
||||
path = getenv("HOME");
|
||||
if (path.starts_with("~/")) {
|
||||
const char *home = getenv("HOME");
|
||||
if (home)
|
||||
path = std::string(home) + path.substr(1);
|
||||
}
|
||||
if (first != std::string::npos)
|
||||
if (chdir(path.c_str()) == -1)
|
||||
throw ed_error("Can't change directory.");
|
||||
if (chdir(path.c_str()) == -1)
|
||||
throw ed_error("Can't change directory.");
|
||||
},
|
||||
}
|
||||
);
|
||||
ctx.functions.insert(
|
||||
"pwd",
|
||||
Function{
|
||||
.address_kind = Function::AddressKind::None,
|
||||
.argument_kind = Function::ArgumentKind::None,
|
||||
.input_mode = Function::InputMode::None,
|
||||
.desc = "Print directory.",
|
||||
.default_address = "",
|
||||
.accept_zero = false,
|
||||
.pre_text_mode = nullptr,
|
||||
.handle = [](BEd &ctx, const buffer::Address &, vase::Shard *, const Argument &, std::vector<buffer::Line> *) {
|
||||
char cwd[PATH_MAX];
|
||||
if (!getcwd(cwd, sizeof(cwd)))
|
||||
throw ed_error("Directory changed, but couldn't determine current directory.");
|
||||
throw ed_error("Can't determine current directory.");
|
||||
ctx.io.write_line(cwd);
|
||||
},
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ void Function::register_posix(BEd &ctx) {
|
||||
.input_mode = Function::InputMode::None,
|
||||
.desc = "Read from file into buffer.",
|
||||
.default_address = "$",
|
||||
.accept_zero = false,
|
||||
.accept_zero = true,
|
||||
.pre_text_mode = nullptr,
|
||||
.handle = [](BEd &ctx, const buffer::Address &addr_, vase::Shard *, const Argument &arg, std::vector<buffer::Line> *) {
|
||||
auto &addr = std::get<buffer::Line>(addr_);
|
||||
|
||||
Reference in New Issue
Block a user