diff options
author | Itamar <itamar8910@gmail.com> | 2020-03-15 18:20:19 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-15 19:09:24 +0100 |
commit | bbe50577f8a5e86b60ed7d3b37a3c1ec09255146 (patch) | |
tree | 6e14be7a1e6ac870d38a7aca894ff0797eaf544b | |
parent | 7967c80222a18db5da815201d0d58afdf8b0df18 (diff) | |
download | serenity-bbe50577f8a5e86b60ed7d3b37a3c1ec09255146.zip |
Terminal: Add -d option for specifying working directory
-rw-r--r-- | Applications/Terminal/main.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp index 6de7f1db73..324f965dc4 100644 --- a/Applications/Terminal/main.cpp +++ b/Applications/Terminal/main.cpp @@ -197,12 +197,21 @@ int main(int argc, char** argv) } const char* command_to_execute = nullptr; + const char* working_directory_chars = nullptr; Core::ArgsParser args_parser; args_parser.add_option(command_to_execute, "Execute this command inside the terminal", nullptr, 'e', "command"); + args_parser.add_option(working_directory_chars, "Set the working directory", nullptr, 'd', "directory"); + args_parser.parse(argc, argv); - if (chdir(get_current_user_home_path().characters()) < 0) + String working_directory(working_directory_chars); + + if (working_directory.is_empty()) { + working_directory = get_current_user_home_path(); + } + + if (chdir(working_directory.characters()) < 0) perror("chdir"); int ptm_fd = posix_openpt(O_RDWR | O_CLOEXEC); |