Skip to content

Commit

Permalink
Included the initial working directory in serialized session state.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmecham committed Apr 21, 2018
1 parent 048447c commit 4a5c8b6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## master

* Include the initial working directory in serialized session state.
* Eliminated a workspace lookup on pty-based exits.
* Removed the polyfill for ResizeObserver and set the required Atom version to 1.19+ to ensure the presence of native support.

Expand Down
60 changes: 33 additions & 27 deletions lib/terminal-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,10 @@ export default class TerminalSession {
return spawnPty(this.shellPath, shellArguments, {
name: 'xterm-color',
env: this.sanitizedEnvironment,
cwd: this._getWorkingDirectory()
cwd: this.workingDirectory
});
}

//
// Select a working directory for a new terminal.
// Uses the project folder of the currently active file, if any,
// otherwise falls back to the first project's folder, if any,
// or the user's home directory.
//
_getWorkingDirectory() {
const activeItem = atom.workspace.getActivePaneItem();
if (activeItem
&& activeItem.buffer
&& activeItem.buffer.file
&& activeItem.buffer.file.path) {
return atom.project.relativizePath(activeItem.buffer.file.path)[0];
} else {
const projectPaths = atom.project.getPaths();
let cwd;
if (projectPaths.length > 0) {
cwd = projectPaths[0];
} else {
cwd = process.env.HOME;
}
return path.resolve(cwd);
}
}

//
// Clears the contents of the terminal buffer. This is a simple proxy to the
// `clear()` function on the Xterm instance.
Expand Down Expand Up @@ -107,7 +82,8 @@ export default class TerminalSession {
config: {
sanitizeEnvironment: this.sanitizedEnvironmentKeys,
shellArgs: this.shellArguments,
shellPath: this.shellPath
shellPath: this.shellPath,
workingDirectory: this.workingDirectory
}
};
}
Expand All @@ -133,6 +109,30 @@ export default class TerminalSession {
return this.emitter.on('did-destroy', callback);
}

//
// Select a working directory for a new terminal.
// Uses the project folder of the currently active file, if any,
// otherwise falls back to the first project's folder, if any,
// or the user's home directory.
//
_getWorkingDirectory() {
if (this._workingDirectory) return this._workingDirectory;

const activeItem = atom.workspace.getActivePaneItem();
if (activeItem && activeItem.buffer && activeItem.buffer.file && activeItem.buffer.file.path) {
return atom.project.relativizePath(activeItem.buffer.file.path)[0];
}

const projectPaths = atom.project.getPaths();
let cwd;
if (projectPaths.length > 0) {
cwd = projectPaths[0];
} else {
cwd = process.env.HOME;
}
return path.resolve(cwd);
}

get sanitizedEnvironment() {
const sanitizedEnvironment = Object.assign({}, process.env);
const variablesToDelete = this.sanitizedEnvironmentKeys;
Expand Down Expand Up @@ -167,6 +167,12 @@ export default class TerminalSession {
|| atom.config.get('terminal-tab.shellSettings.sanitizeEnvironment');
}

get workingDirectory() {
if (this._workingDirectory) return this._workingDirectory;
return this._workingDirectory = this.config.workingDirectory
|| this._getWorkingDirectory();
}

getDefaultLocation() {
return atom.config.get('terminal-tab.defaultLocation');
}
Expand Down

0 comments on commit 4a5c8b6

Please sign in to comment.