diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-09-16 05:13:04 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-26 21:28:35 +0200 |
commit | b3dd97a6944f57edfd984a2ab046c82ad8b34621 (patch) | |
tree | 940e0213733bd2e86cb8ef6eaaf9754eea64d3c1 /Shell/main.cpp | |
parent | 6e6be8e56e76a1f7ce6245a4fc62b30fc35ad1ab (diff) | |
download | serenity-b3dd97a6944f57edfd984a2ab046c82ad8b34621.zip |
Shell: Add a (very basic) formatter
Diffstat (limited to 'Shell/main.cpp')
-rw-r--r-- | Shell/main.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Shell/main.cpp b/Shell/main.cpp index ff26634913..f605730531 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -200,21 +200,34 @@ int main(int argc, char** argv) const char* file_to_read_from = nullptr; Vector<const char*> script_args; bool skip_rc_files = false; + const char* format = nullptr; Core::ArgsParser parser; parser.add_option(command_to_run, "String to read commands from", "command-string", 'c', "command-string"); parser.add_option(skip_rc_files, "Skip running shellrc files", "skip-shellrc", 0); + parser.add_option(format, "File to format", "format", 0, "file"); parser.add_positional_argument(file_to_read_from, "File to read commands from", "file", Core::ArgsParser::Required::No); parser.add_positional_argument(script_args, "Extra argumets to pass to the script (via $* and co)", "argument", Core::ArgsParser::Required::No); parser.parse(argc, argv); + if (format) { + auto file = Core::File::open(format, Core::IODevice::ReadOnly); + if (file.is_error()) { + fprintf(stderr, "Error: %s", file.error().characters()); + return 1; + } + + ssize_t cursor = -1; + puts(shell->format(file.value()->read_all(), cursor).characters()); + return 0; + } + if (getsid(getpid()) == 0) { if (setsid() < 0) { perror("setsid"); // Let's just hope that it's ok. } - } shell->current_script = argv[0]; |