Skip to content

Commit

Permalink
vercel#3000: Adding logic to support working directory config
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushikchaubal committed Jul 26, 2019
1 parent c13c8a5 commit b021144
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/config/config-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ module.exports = {
// custom CSS to embed in the terminal window
termCSS: '',

// set custom startup directory (must be an absolute path)
workingDirectory: '',

// if you're using a Linux setup which show native menus, set to false
// default: `true` on Linux, `true` on Windows, ignored on macOS
showHamburgerMenu: '',
Expand Down
12 changes: 10 additions & 2 deletions app/ui/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const fileUriToPath = require('file-uri-to-path');
const isDev = require('electron-is-dev');
const updater = require('../updater');
const toElectronBackgroundColor = require('../utils/to-electron-background-color');
const {icon, homeDirectory} = require('../config/paths');
const {icon, homeDirectory, cfgDir} = require('../config/paths');
const createRPC = require('../rpc');
const notify = require('../notify');
const fetchNotifications = require('../notifications');
Expand Down Expand Up @@ -52,6 +52,14 @@ module.exports = class Window {
window.setBackgroundColor(toElectronBackgroundColor(cfg_.backgroundColor || '#000'));
};

// set working directory
let workingDirectory = cfgDir;
if (process.argv[1] && isAbsolute(process.argv[1])) {
workingDirectory = process.argv[1];
} else if (cfg.workingDirectory && isAbsolute(cfg.workingDirectory)) {
workingDirectory = cfg.workingDirectory;
}

// config changes
const cfgUnsubscribe = app.config.subscribe(() => {
const cfg_ = app.plugins.getDecoratedConfig();
Expand Down Expand Up @@ -103,7 +111,7 @@ module.exports = class Window {
{
rows: 40,
cols: 100,
cwd: process.argv[1] && isAbsolute(process.argv[1]) ? process.argv[1] : homeDirectory,
cwd: workingDirectory,
splitDirection: undefined,
shell: cfg.shell,
shellArgs: cfg.shellArgs && Array.from(cfg.shellArgs)
Expand Down

0 comments on commit b021144

Please sign in to comment.