1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-04 15:45:25 +02:00

Use dynamic prompt generation for ssh even outside ServiceCommandShell

This commit is contained in:
Martin Oberhuber 2006-08-09 11:41:01 +00:00
parent c129e89e79
commit a1a46ef13e
2 changed files with 32 additions and 8 deletions

View file

@ -90,6 +90,11 @@ public class SshHostShell extends AbstractHostShell implements IHostShell {
*/
protected void start(IProgressMonitor monitor)
{
//TODO Move stuff from constructor to here
//TODO Set up environment variables fro proper prompting, e.g. like dstore
//varTable.put("PS1","$PWD/>");
//varTable.put("COLUMNS","256");
//alias ls='ls -1'
}
public boolean isActive() {
@ -105,8 +110,19 @@ public class SshHostShell extends AbstractHostShell implements IHostShell {
return false;
}
private static final Pattern cdCommands = Pattern.compile("\\A\\s*(cd|chdir|ls)\\b"); //$NON-NLS-1$
public String getPromptCommand() {
return "echo $PWD'>'"; //$NON-NLS-1$
}
public void writeToShell(String command) {
if (isActive()) {
if ("#break".equals(command)) { //$NON-NLS-1$
command = "\u0003"; //Unicode 3 == Ctrl+C //$NON-NLS-1$
} else if (cdCommands.matcher(command).find()) {
command += "\r\n" + getPromptCommand(); //$NON-NLS-1$
}
if (!fShellWriter.sendCommand(command)) {
//exception occurred: terminate writer thread, cancel connection
exit();

View file

@ -17,7 +17,6 @@
package org.eclipse.rse.subsystems.shells.ssh;
import java.util.ArrayList;
import java.util.regex.Pattern;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@ -30,6 +29,7 @@ import org.eclipse.rse.services.shells.IHostShell;
import org.eclipse.rse.services.shells.IHostShellChangeEvent;
import org.eclipse.rse.services.ssh.shell.ParsedOutput;
import org.eclipse.rse.services.ssh.shell.Patterns;
import org.eclipse.rse.services.ssh.shell.SshHostShell;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
import org.eclipse.rse.subsystems.shells.core.model.ISystemOutputRemoteTypes;
import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem;
@ -140,20 +140,28 @@ public class SshServiceCommandShell extends ServiceCommandShell implements ISyst
_lastRefreshJob.schedule();
}
}
private static final Pattern cdCommands = Pattern.compile("\\A\\s*(cd|chdir|ls)\\b"); //$NON-NLS-1$
/**
* Return the prompt command, such that lines ending with the
* prompt command can be removed from output.
* Should be overridden in case the IHostShell used for this
* service is not an SshHostShell.
* @return String promptCommand
*/
protected String getPromptCommand() {
return "echo $PWD'>'"; //$NON-NLS-1$
IHostShell shell = getHostShell();
assert shell instanceof SshHostShell;
if (shell instanceof SshHostShell) {
return ((SshHostShell)shell).getPromptCommand();
}
//return something impossible such that nothing is ever matched
return "\uffff"; //$NON-NLS-1$
}
public void writeToShell(String cmd)
{
_curCommand = cmd;
_patterns.update(cmd);
if (cdCommands.matcher(cmd).find()) {
cmd += "\r\n" + getPromptCommand(); //$NON-NLS-1$
}
super.writeToShell(cmd);
}