Skip to content
Permalink
Browse files

Add initial directory setting for WSL and Cygwin sessions

issue #184
  • Loading branch information...
sedwards2009 committed Apr 28, 2019
1 parent b430103 commit 50323af2b4b189ebbacde0131b70e64df2ddb325
@@ -109,10 +109,14 @@ export class CygwinProxySessionBackend implements SessionBackend {
exe: shell,
args,
env: ptyEnv,
cols: cols,
rows: rows
cols,
rows,
};

if (sessionConfig.initialDirectory != null && sessionConfig.initialDirectory !== "") {
options.cwd = sessionConfig.initialDirectory;
}

const pythonExe = this._findCygwinPython(sessionConfig.cygwinPath);
if (pythonExe == null) {
throw new Error(
@@ -49,7 +49,8 @@ interface CreatePtyMessage extends ProxyMessage {
columns: number;
env: { [key: string]: string; };
extraEnv: { [key: string]: string; };

cwd: string;

// the id field is not user for this message type.
}

@@ -244,7 +245,7 @@ export abstract class ProxyPtyConnector {
const pty = new ProxyPty(this._sendMessage.bind(this));
this._ptys.push(pty);
const msg: CreatePtyMessage = { type: TYPE_CREATE, argv: [file, ...args], rows: rows, columns: columns,
id: NULL_ID, env: options.env, extraEnv: options.extraEnv == null ? {} : options.extraEnv};
id: NULL_ID, env: options.env, extraEnv: options.extraEnv == null ? {} : options.extraEnv, cwd: options.cwd || null};
this._sendMessage(null, msg);
return pty;
}
@@ -67,7 +67,7 @@ export class WslProxySessionBackend implements SessionBackend {
const defaultShell = "/bin/bash";
let shell = sessionConfig.useDefaultShell ? defaultShell : sessionConfig.shell;
const args = ["-l"].concat(ShellStringParser(sessionConfig.args));

const extraPtyEnv = {
TERM: "xterm-256color"
};
@@ -81,10 +81,14 @@ export class WslProxySessionBackend implements SessionBackend {
args,
env: null,
extraEnv: extraPtyEnv,
cols: cols,
rows: rows
cols,
rows
};

if (sessionConfig.initialDirectory != null && sessionConfig.initialDirectory !== "") {
options.cwd = sessionConfig.initialDirectory;
}

const connector = this._getConnector();
return connector.spawn(options);
}
@@ -316,14 +316,21 @@ def process_create_command(cmd):

env.update(cmd.get("extraEnv", {}))

cwd = cmd["cwd"]
if cwd == "" or cwd is None:
cwd = None
else:
if not os.path.exists(cwd):
cwd = None

# Fix up the PATH variable on cygwin.
if sys.platform == "cygwin":
if "Path" in env and "PATH" not in env:
env["PATH"] = env["Path"]
del env["Path"]
env["PATH"] = cygwin_convert_path_variable(env["PATH"])
try:
pty = ptyprocess.PtyProcess.spawn(cmd["argv"], dimensions=(rows, columns), env=env) #cwd=, )
pty = ptyprocess.PtyProcess.spawn(cmd["argv"], dimensions=(rows, columns), env=env, cwd=cwd)
except FileNotFoundError:
pty = DeadPty(cmd["argv"])

@@ -62,7 +62,8 @@ export function getCygwinProxySessionEditorClass(context: ExtensionContext): any
useDefaultShell: true,
shell: "",
cygwinPath: cygwinInstallationDir,
args: ""
args: "",
initialDirectory: "",
};
}

@@ -71,6 +72,7 @@ export function getCygwinProxySessionEditorClass(context: ExtensionContext): any
this._ui.shell = fixedConfig.shell;
this._ui.cygwinPath = fixedConfig.cygwinPath;
this._ui.args = fixedConfig.args;
this._ui.initialDirectory = fixedConfig.initialDirectory || "";
}

_dataChanged(): void {
@@ -79,7 +81,8 @@ export function getCygwinProxySessionEditorClass(context: ExtensionContext): any
useDefaultShell: this._ui.useDefaultShell === 1,
shell: this._ui.shell,
cygwinPath: this._ui.cygwinPath,
args: this._ui.args
args: this._ui.args,
initialDirectory: this._ui.initialDirectory,
};
this._checkPaths();
this.updateSessionConfiguration(changes);
@@ -43,6 +43,9 @@ import { trimBetweenTags } from 'extraterm-trim-between-tags';
<label for="name">Arguments:</label>
<input type="text" class="form-control" name="args" v-model="args">
<label for="initialDirectory">Initial Directory:</label>
<input type="text" name="initialDirectory" v-model="initialDirectory">
</div>`)
})
export class CygwinProxySessionEditorUi extends Vue {
@@ -53,4 +56,5 @@ export class CygwinProxySessionEditorUi extends Vue {
cygwinPath = "";
cygwinPathErrorMsg = "";
args: string = "";
initialDirectory = "";
}
@@ -57,7 +57,8 @@ export function getWslProxySessionEditorClass(context: ExtensionContext): any {
name: config.name,
useDefaultShell: true,
shell: "",
args: ""
args: "",
initialDirectory: "",
};
}

@@ -66,14 +67,16 @@ export function getWslProxySessionEditorClass(context: ExtensionContext): any {
this._ui.shell = fixedConfig.shell;
this._ui.etcShells = [...etcShells];
this._ui.args = fixedConfig.args;
this._ui.initialDirectory = fixedConfig.initialDirectory || "";
}

_dataChanged(): void {
const changes = {
name: this._ui.name,
useDefaultShell: this._ui.useDefaultShell === 1,
shell: this._ui.shell,
args: this._ui.args
args: this._ui.args,
initialDirectory: this._ui.initialDirectory,
};
this.updateSessionConfiguration(changes);
}
@@ -40,6 +40,9 @@ import { trimBetweenTags } from 'extraterm-trim-between-tags';
<label for="name">Arguments:</label>
<input type="text" name="args" v-model="args">
<label for="initialDirectory">Initial Directory:</label>
<input type="text" name="initialDirectory" v-model="initialDirectory">
</div>
`)
})
@@ -50,4 +53,5 @@ export class WslProxySessionEditorUi extends Vue {
shellErrorMsg = "";
etcShells = [];
args = "";
initialDirectory = "";
}

0 comments on commit 50323af

Please sign in to comment.
You can’t perform that action at this time.