Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a editor FileSystem dock action to open a terminal in selected folder #85923

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Dec 8, 2023

This is useful to enter some commands without having to open a separate terminal and cd to the project folder.

Tested on:

  • Windows: PowerShell, cmd, Hyper
  • macOS: Terminal.app, iTerm2
  • Linux: Konsole, kitty

Paths with spaces have been tested in all scenarios listed above and are confirmed to be working.

Testing on more Linux terminal emulators is welcome.

Preview

Screenshot_20231208_141627

Screenshot_20231208_141652

@Calinou Calinou added this to the 4.x milestone Dec 8, 2023
@Calinou Calinou requested review from a team as code owners December 8, 2023 15:04
Comment on lines +2188 to +2191
// 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");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't been able to resolve this yet. Note that this output only appears in the terminal's stdout when running Godot from a terminal, not in the editor Output panel.

// Prepend default arguments based on the terminal emulator name.
// Use `String.get_basename().to_lower()` to handle Windows' case-insensitive paths
// with optional file extensions for executables in `PATH`.
if (chosen_terminal_emulator.get_basename().to_lower() == "powershell") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be equal to pwsh, if the user has a newer version of Powershell (i.e. "Powershell Core" in addition to "Windows Powershell") installed. Same command line arguments would apply.

Copy link
Member Author

@Calinou Calinou Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Windows itself still calls powershell by default (in the Windows + X menu for instance), but you should be able to specify pwsh in the custom terminal name editor setting. I can modify the class reference accordingly.

editor/filesystem_dock.cpp Outdated Show resolved Hide resolved
@Calinou Calinou force-pushed the editor-filesystem-dock-add-open-in-terminal branch from 15e8505 to b292a96 Compare December 16, 2023 21:27
Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks ok on the editor side, can't say much about the FILE_OPEN_IN_TERMINAL code, as there is lots of platform-specific stuff happening in there.

Personally I'm indifferent to the feature. If I need git I just open the project in VS Code, which comes with its own terminal. Also from what I understand, this option is mostly useful in project's root folder, so it could be "Open Project in Terminal" in the Project menu instead of making the file menu longer. But well, either way is fine.

@Calinou Calinou changed the title Add a editor FileSystem dock action to open a terminal in selcted folder Add a editor FileSystem dock action to open a terminal in selected folder Dec 19, 2023
@Calinou Calinou force-pushed the editor-filesystem-dock-add-open-in-terminal branch from b292a96 to e17a29c Compare December 19, 2023 13:42
@Calinou
Copy link
Member Author

Calinou commented Dec 19, 2023

I force-pushed to fix a typo in the commit message; no other changes were made.

editor/filesystem_dock.cpp Outdated Show resolved Hide resolved
editor/filesystem_dock.cpp Outdated Show resolved Hide resolved
editor/filesystem_dock.cpp Show resolved Hide resolved
doc/classes/EditorSettings.xml Outdated Show resolved Hide resolved
@AThousandShips
Copy link
Member

Can confirm that this works on Windows 11 with PowerShell, both for folders and files (open containing folder)

…lder

This is useful to enter some commands without having to open a separate
terminal and `cd` to the project folder.
@Calinou Calinou force-pushed the editor-filesystem-dock-add-open-in-terminal branch from e17a29c to 0e97acf Compare December 19, 2023 14:04
@YuriSizov YuriSizov modified the milestones: 4.x, 4.3 Dec 22, 2023
@YuriSizov YuriSizov merged commit 13d34d6 into godotengine:master Dec 22, 2023
15 checks passed
@YuriSizov
Copy link
Contributor

Thanks!

@Calinou Calinou deleted the editor-filesystem-dock-add-open-in-terminal branch January 7, 2024 16:08
@panreyes
Copy link

panreyes commented Jan 8, 2024

I'm a bit late to the party, but I would have suggested adding another really useful option for Windows:
Showing the shell contextual menu of certain folder/file.

It would be pretty useful, as we would have access to all Windows shell extensions just right there.

This idea comes from TortoiseGit:
image

The function to call would be SHCreateDefaultContextMenu ( https://learn.microsoft.com/es-es/windows/win32/api/shlobj_core/nf-shlobj_core-shcreatedefaultcontextmenu ) but, after having a look into it, seems that it is not an easy task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a "Open Terminal Here" context menu option to the FileSystem dock
6 participants