diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2024-02-15 15:44:59 +0100 |
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-02-15 15:44:59 +0100 |
| commit | ce971c268241eb6d0d6a04095758090d19c7aeab (patch) | |
| tree | a7bcac3bbec9f25747f58bceaa5c7a63e3011702 | |
| parent | 09df8f4a560b69d44e676ec8ec1f6b8fd866cd5e (diff) | |
| parent | 8e8f8e92fbc0cbdbacd976121f5db606c9bf6200 (diff) | |
| download | redot-engine-ce971c268241eb6d0d6a04095758090d19c7aeab.tar.gz | |
Merge pull request #88173 from capnm/240210-fix-fsdock-open_terminal
FileSystem dock: Fix opening a Linux terminal
| -rw-r--r-- | editor/filesystem_dock.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 88bd90be98..dde7ddd32d 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -2128,7 +2128,8 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected terminal_emulators.push_back(terminal_emulator_setting); } - String arguments = EDITOR_GET("filesystem/external_programs/terminal_emulator_flags"); + String flags = EDITOR_GET("filesystem/external_programs/terminal_emulator_flags"); + String arguments = flags; if (arguments.is_empty()) { // NOTE: This default value is ignored further below if the terminal executable is `powershell` or `cmd`, // due to these terminals requiring nonstandard syntax to start in a specified folder. @@ -2138,16 +2139,13 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected #ifdef LINUXBSD_ENABLED String chosen_terminal_emulator; for (const String &terminal_emulator : terminal_emulators) { + String pipe; List<String> test_args; // Required for `execute()`, as it doesn't accept `Vector<String>`. - test_args.push_back("-v"); - test_args.push_back(terminal_emulator); - // Silence command name being printed when found. (stderr is already silenced by `OS::execute()` by default.) - // FIXME: This doesn't appear to silence stdout. - test_args.push_back(">"); - test_args.push_back("/dev/null"); - int exit_code = 0; - const Error err = OS::get_singleton()->execute("command", test_args, nullptr, &exit_code); - if (err == OK && exit_code == EXIT_SUCCESS) { + test_args.push_back("-cr"); + test_args.push_back("command -v " + terminal_emulator); + const Error err = OS::get_singleton()->execute("bash", test_args, &pipe); + // Check if a path to the terminal executable exists. + if (err == OK && pipe.contains("/")) { chosen_terminal_emulator = terminal_emulator; break; } else if (err == ERR_CANT_FORK) { @@ -2164,8 +2162,14 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected // Prepend default arguments based on the terminal emulator name. // Use `String.ends_with()` so that installations in non-default paths // or `/usr/local/bin` are detected correctly. - if (chosen_terminal_emulator.ends_with("konsole")) { - terminal_emulator_args.push_back("--workdir"); + if (flags.is_empty()) { + if (chosen_terminal_emulator.ends_with("konsole")) { + terminal_emulator_args.push_back("--workdir"); + } else if (chosen_terminal_emulator.ends_with("gnome-terminal")) { + terminal_emulator_args.push_back("--working-directory"); + } else if (chosen_terminal_emulator.ends_with("urxvt")) { + terminal_emulator_args.push_back("-cd"); + } } #endif |
