From 211fb2858f1d8e12e0e8b42860fb97e9c1ebfe8d Mon Sep 17 00:00:00 2001 From: danthe1st Date: Mon, 14 Sep 2026 18:33:46 +0200 Subject: [PATCH 1/2] allow specifying default local terminal shell on Windows systems --- .../local/launcher/LocalLauncherDelegate.java | 31 +-- .../view/ui/internal/Messages.properties | 2 +- .../internal/preferences/PreferencePage.java | 211 ++++++++++-------- 3 files changed, 129 insertions(+), 115 deletions(-) diff --git a/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java b/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java index 8e638cd36e0..ae34e1d46ff 100644 --- a/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java +++ b/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java @@ -270,22 +270,23 @@ public T getAdapter(Class adapter) { * @return The default shell to launch. */ private final File defaultShell() { - String shell = null; + String shell = IPreferenceKeys.getPreferences() + .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX); + String defaultShellEnvironmentVariable; + String defaultShellIfNotSet; if (Platform.OS_WIN32.equals(Platform.getOS())) { - if (System.getenv("ComSpec") != null && !"".equals(System.getenv("ComSpec").trim())) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - shell = System.getenv("ComSpec").trim(); //$NON-NLS-1$ - } else { - shell = "cmd.exe"; //$NON-NLS-1$ - } + defaultShellEnvironmentVariable = "ComSpec"; //$NON-NLS-1$ + defaultShellIfNotSet = "cmd.exe"; //$NON-NLS-1$ + } else { + defaultShellEnvironmentVariable = "SHELL"; //$NON-NLS-1$ + defaultShellIfNotSet = "/bin/sh"; //$NON-NLS-1$ } - if (shell == null) { - shell = IPreferenceKeys.getPreferences().getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX); - if (shell == null || "".equals(shell)) { //$NON-NLS-1$ - if (System.getenv("SHELL") != null && !"".equals(System.getenv("SHELL").trim())) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - shell = System.getenv("SHELL").trim(); //$NON-NLS-1$ - } else { - shell = "/bin/sh"; //$NON-NLS-1$ - } + if (shell == null || shell.isEmpty()) { + if (System.getenv(defaultShellEnvironmentVariable) != null + && !"".equals(System.getenv(defaultShellEnvironmentVariable).trim())) { //$NON-NLS-1$ + shell = System.getenv(defaultShellEnvironmentVariable).trim(); + } else { + shell = defaultShellIfNotSet; } } @@ -313,7 +314,7 @@ public ITerminalConnector createTerminalConnector(Map properties } String arguments = (String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ARGS); - if (arguments == null && !Platform.OS_WIN32.equals(Platform.getOS())) { + if (arguments == null) { arguments = IPreferenceKeys.getPreferences() .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS); } diff --git a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/Messages.properties b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/Messages.properties index d33fef3009e..18b02f48967 100644 --- a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/Messages.properties +++ b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/Messages.properties @@ -118,5 +118,5 @@ PreferencePage_command_label=Shell Command PreferencePage_command_button_browse=&Browse... PreferencePage_command_invalid=Selected shell command is not a file or is not readable or executable. PreferencePage_command_note_label=Note: -PreferencePage_command_note_text=Leave the shell command empty to fallback to the SHELL environment variable or if not set, to /bin/sh. +PreferencePage_command_note_text=Leave the shell command empty to fallback to the {0} environment variable or if not set, to {1}. PreferencePage_command_arguments_label=Arguments: diff --git a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/preferences/PreferencePage.java b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/preferences/PreferencePage.java index 138d7b28174..f2fc0c3c4d6 100644 --- a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/preferences/PreferencePage.java +++ b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/preferences/PreferencePage.java @@ -43,6 +43,7 @@ import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.window.Window; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -118,91 +119,7 @@ protected Control createContents(final Composite parent) { label.setText(Messages.PreferencePage_label); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - if (!Platform.OS_WIN32.equals(Platform.getOS())) { - Group group = new Group(panel, SWT.NONE); - group.setText(Messages.PreferencePage_command_label); - group.setLayout(new GridLayout(2, false)); - group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); - - command = new Text(group, SWT.SINGLE | SWT.BORDER); - command.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - command.addModifyListener(e -> { - boolean valid = true; - String message = null; - - String text = command.getText(); - if (text != null && !"".equals(text.trim())) { //$NON-NLS-1$ - IPath p = new Path(text.trim()); - valid = p.toFile().isFile() && p.toFile().canRead() && p.toFile().canExecute(); - if (!valid) { - message = Messages.PreferencePage_command_invalid; - } - } - - setValid(valid); - setErrorMessage(message); - }); - - commandBrowseButton = new Button(group, SWT.PUSH); - commandBrowseButton.setText(Messages.PreferencePage_command_button_browse); - layoutData = new GridData(SWT.FILL, SWT.CENTER, false, false); - layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 14); - commandBrowseButton.setLayoutData(layoutData); - commandBrowseButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - FileDialog dialog = new FileDialog(parent.getShell(), SWT.OPEN); - - String text = command.getText(); - if (text != null && !"".equals(text.trim())) { //$NON-NLS-1$ - IPath p = new Path(text); - - if (p.toFile().isFile() || !p.toFile().exists()) { - dialog.setFilterPath(p.removeLastSegments(1).toOSString()); - dialog.setFileName(p.lastSegment()); - } else if (p.toFile().isDirectory()) { - dialog.setFilterPath(p.toOSString()); - } - } - - String selected = dialog.open(); - if (selected != null) { - IPath sp = new Path(selected); - command.setText(sp.toOSString()); - } - } - }); - - String cmd = UIPlugin.getScopedPreferences() - .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX); - if (cmd != null && !"".equals(cmd)) { //$NON-NLS-1$ - command.setText(new Path(cmd).toOSString()); - } - - Composite argsPanel = new Composite(group, SWT.NONE); - GridLayout layout = new GridLayout(2, false); - layout.marginHeight = 0; - layout.marginWidth = 0; - argsPanel.setLayout(layout); - layoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); - layoutData.horizontalSpan = 2; - argsPanel.setLayoutData(layoutData); - - label = new Label(argsPanel, SWT.NONE); - label.setText(Messages.PreferencePage_command_arguments_label); - - arguments = new Text(argsPanel, SWT.SINGLE | SWT.BORDER); - arguments.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - - String args = UIPlugin.getScopedPreferences() - .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS); - if (args != null && !"".equals(args)) { //$NON-NLS-1$ - arguments.setText(args); - } - - NoteCompositeHelper.createNoteComposite(group.getFont(), group, Messages.PreferencePage_command_note_label, - Messages.PreferencePage_command_note_text); - } + addShellCommandSection(parent, gc, panel); Group group = new Group(panel, SWT.NONE); group.setText(Messages.PreferencePage_workingDir_label); @@ -591,6 +508,104 @@ public void addListener(ILabelProviderListener listener) { return panel; } + private void addShellCommandSection(final Composite parent, final GC gc, Composite panel) { + GridData layoutData; + Label label; + Group group = new Group(panel, SWT.NONE); + group.setText(Messages.PreferencePage_command_label); + group.setLayout(new GridLayout(2, false)); + group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); + + command = new Text(group, SWT.SINGLE | SWT.BORDER); + command.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + command.addModifyListener(e -> { + boolean valid = true; + String message = null; + + String text = command.getText(); + if (text != null && !"".equals(text.trim())) { //$NON-NLS-1$ + IPath p = new Path(text.trim()); + valid = p.toFile().isFile() && p.toFile().canRead() && p.toFile().canExecute(); + if (!valid) { + message = Messages.PreferencePage_command_invalid; + } + } + + setValid(valid); + setErrorMessage(message); + }); + + commandBrowseButton = new Button(group, SWT.PUSH); + commandBrowseButton.setText(Messages.PreferencePage_command_button_browse); + layoutData = new GridData(SWT.FILL, SWT.CENTER, false, false); + layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 14); + commandBrowseButton.setLayoutData(layoutData); + commandBrowseButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + FileDialog dialog = new FileDialog(parent.getShell(), SWT.OPEN); + + String text = command.getText(); + if (text != null && !"".equals(text.trim())) { //$NON-NLS-1$ + IPath p = new Path(text); + + if (p.toFile().isFile() || !p.toFile().exists()) { + dialog.setFilterPath(p.removeLastSegments(1).toOSString()); + dialog.setFileName(p.lastSegment()); + } else if (p.toFile().isDirectory()) { + dialog.setFilterPath(p.toOSString()); + } + } + + String selected = dialog.open(); + if (selected != null) { + IPath sp = new Path(selected); + command.setText(sp.toOSString()); + } + } + }); + + String cmd = UIPlugin.getScopedPreferences().getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX); + if (cmd != null && !"".equals(cmd)) { //$NON-NLS-1$ + command.setText(new Path(cmd).toOSString()); + } + + Composite argsPanel = new Composite(group, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + argsPanel.setLayout(layout); + layoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); + layoutData.horizontalSpan = 2; + argsPanel.setLayoutData(layoutData); + + label = new Label(argsPanel, SWT.NONE); + label.setText(Messages.PreferencePage_command_arguments_label); + + arguments = new Text(argsPanel, SWT.SINGLE | SWT.BORDER); + arguments.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + String args = UIPlugin.getScopedPreferences() + .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS); + if (args != null && !"".equals(args)) { //$NON-NLS-1$ + arguments.setText(args); + } + + String defaultShellEnvironmentVariable; + String defaultShellIfNotSet; + if (Platform.OS_WIN32.equals(Platform.getOS())) { + defaultShellEnvironmentVariable = "ComSpec"; //$NON-NLS-1$ + defaultShellIfNotSet = "cmd.exe"; //$NON-NLS-1$ + } else { + defaultShellEnvironmentVariable = "SHELL"; //$NON-NLS-1$ + defaultShellIfNotSet = "/bin/sh"; //$NON-NLS-1$ + } + + NoteCompositeHelper.createNoteComposite(group.getFont(), group, Messages.PreferencePage_command_note_label, + NLS.bind(Messages.PreferencePage_command_note_text, defaultShellEnvironmentVariable, + defaultShellIfNotSet)); + } + /** * Updates the button states. */ @@ -614,10 +629,8 @@ protected void updateButtons() { @Override protected void performDefaults() { - if (!Platform.OS_WIN32.equals(Platform.getOS())) { - command.setText(""); //$NON-NLS-1$ - arguments.setText(""); //$NON-NLS-1$ - } + command.setText(""); //$NON-NLS-1$ + arguments.setText(""); //$NON-NLS-1$ String initialCwd = UIPlugin.getScopedPreferences() .getDefaultString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD); @@ -646,16 +659,16 @@ protected void performDefaults() { @Override public boolean performOk() { - if (!Platform.OS_WIN32.equals(Platform.getOS())) { - String text = command.getText(); - IPath p = new Path(text.trim()); - UIPlugin.getScopedPreferences().setValue(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX, - p.toFile().isFile() && p.toFile().canRead() && p.toFile().canExecute() ? p.toOSString() : ""); //$NON-NLS-1$ - - text = arguments.getText(); - UIPlugin.getScopedPreferences().setValue(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS, - !"".equals(text.trim()) ? text.trim() : ""); //$NON-NLS-1$ //$NON-NLS-2$ - } + String commandText = command.getText(); + IPath commandPath = new Path(commandText.trim()); + UIPlugin.getScopedPreferences().setValue(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX, + commandPath.toFile().isFile() && commandPath.toFile().canRead() && commandPath.toFile().canExecute() + ? commandPath.toOSString() + : ""); //$NON-NLS-1$ + + commandText = arguments.getText(); + UIPlugin.getScopedPreferences().setValue(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS, + !"".equals(commandText.trim()) ? commandText.trim() : ""); //$NON-NLS-1$ //$NON-NLS-2$ String text = workingDir.getText(); if (text == null || Messages.PreferencePage_workingDir_userhome_label.equals(text) || "".equals(text.trim())) { //$NON-NLS-1$ From 14df6bd46e6e3b7d09b3d841d87fc00487fe8ce5 Mon Sep 17 00:00:00 2001 From: Eclipse Platform Bot Date: Tue, 15 Sep 2026 17:33:53 +0000 Subject: [PATCH 2/2] Version bump(s) for 4.42 stream --- .../org.eclipse.terminal.connector.local/META-INF/MANIFEST.MF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminal/bundles/org.eclipse.terminal.connector.local/META-INF/MANIFEST.MF b/terminal/bundles/org.eclipse.terminal.connector.local/META-INF/MANIFEST.MF index c1ea0f73714..0367f64b138 100644 --- a/terminal/bundles/org.eclipse.terminal.connector.local/META-INF/MANIFEST.MF +++ b/terminal/bundles/org.eclipse.terminal.connector.local/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.terminal.connector.local;singleton:=true -Bundle-Version: 1.1.200.qualifier +Bundle-Version: 1.1.300.qualifier Bundle-Activator: org.eclipse.terminal.connector.local.activator.UIPlugin Bundle-Vendor: %providerName Import-Package: org.eclipse.cdt.utils.pty;mandatory:=native,