diff --git a/CHANGELOG.md b/CHANGELOG.md index 764180a..6bb6976 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/terminal-session.js b/lib/terminal-session.js index 9d0ae2f..1cb8c7e 100644 --- a/lib/terminal-session.js +++ b/lib/terminal-session.js @@ -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. @@ -107,7 +82,8 @@ export default class TerminalSession { config: { sanitizeEnvironment: this.sanitizedEnvironmentKeys, shellArgs: this.shellArguments, - shellPath: this.shellPath + shellPath: this.shellPath, + workingDirectory: this.workingDirectory } }; } @@ -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; @@ -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'); }