diff --git a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/IPreferenceKeys.java b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/IPreferenceKeys.java index c09741cfec2..f4a78021b7e 100644 --- a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/IPreferenceKeys.java +++ b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/IPreferenceKeys.java @@ -60,13 +60,15 @@ public interface IPreferenceKeys { public final String PREF_INITIAL_CWD_ECLIPSE_WS = "eclipsews"; //$NON-NLS-1$ /** - * Preference key: Local terminal default shell command on Unix hosts. + * Preference key: Local terminal default shell command. + * Despite the name, this preference key is used regardless of the operating system. * @since 4.1 */ public final String PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX = PREF_TERMINAL + ".localTerminalDefaultShellUnix"; //$NON-NLS-1$ /** - * Preference key: Local terminal default shell command arguments on Unix hosts. + * Preference key: Local terminal default shell command arguments. + * Despite the name, this preference key is used regardless of the operating system. * @since 4.1 */ public final String PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS = PREF_TERMINAL 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 e3598438d6e..fb36a33f166 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 @@ -134,8 +134,7 @@ protected Control createContents(final Composite parent) { 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(); + valid = !resolveCommand(text).isEmpty(); if (!valid) { message = Messages.PreferencePage_command_invalid; } @@ -655,11 +654,11 @@ public boolean performOk() { ScopedPreferenceStore prefs = UIPlugin.getScopedPreferences(); String commandText = command.getText(); - IPath commandPath = new Path(commandText.trim()); - prefs.setValue(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX, - commandPath.toFile().isFile() && commandPath.toFile().canRead() && commandPath.toFile().canExecute() - ? commandPath.toOSString() - : ""); //$NON-NLS-1$ + String commandPath = resolveCommand(commandText); + if (!commandPath.equals(commandText)) { + command.setText(commandPath); + } + prefs.setValue(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX, commandPath); commandText = arguments.getText(); prefs.setValue(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS, @@ -695,6 +694,44 @@ public boolean performOk() { return super.performOk(); } + private String resolveCommand(String commandText) { + String text = commandText.trim(); + if (text.isEmpty()) { + return ""; //$NON-NLS-1$ + } + IPath commandPath = new Path(text); + if (isValidExecutable(commandPath.toFile())) { + return commandPath.toOSString(); + } + + if (commandText.contains("/") || (Platform.OS_WIN32.equals(Platform.getOS()) && commandText.contains("\\"))) { //$NON-NLS-1$//$NON-NLS-2$ + return ""; //$NON-NLS-1$ + } + + String path = System.getenv("PATH"); //$NON-NLS-1$ + if (path == null) { + return ""; //$NON-NLS-1$ + } + + String[] splitted = path.split(Platform.OS_WIN32.equals(Platform.getOS()) ? ";" : ":"); //$NON-NLS-1$//$NON-NLS-2$ + for (String element : splitted) { + File file = new File(element); + if (text.equals(file.getName()) && isValidExecutable(file)) { + return file.getAbsolutePath(); + } + File executable = new File(file, text); + if (isValidExecutable(executable)) { + return executable.getAbsolutePath(); + } + } + + return ""; //$NON-NLS-1$ + } + + private boolean isValidExecutable(File file) { + return file.isFile() && file.canRead() && file.canExecute(); + } + @Override public void dispose() { for (Image i : images.values()) {