Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()) {
Expand Down
Loading