From 011ae3fd5232dd91e6289432869c43dcd15a5441 Mon Sep 17 00:00:00 2001 From: Richard Zhao Date: Tue, 2 Aug 2016 00:49:25 -0700 Subject: [PATCH] Add support for environment variables in config (#534) * Allow env to be specified in config (#424) This is referencing #424. User specified environment variables in the `.hyperterm.js` file are expected under a field named `env`. An example config: ``` module.exports = { config: { ... // Environment variables env: { WHAT_UP: 'heyo', } ... }, plugins: [], localPlugins: [] }; ``` * Add env field to default config --- app/config-default.js | 5 ++++- app/session.js | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/config-default.js b/app/config-default.js index 331f1dfa..bf51c8f8 100644 --- a/app/config-default.js +++ b/app/config-default.js @@ -54,7 +54,10 @@ module.exports = { // the shell to run when spawning a new session (i.e. /usr/local/bin/fish) // if left empty, your system's login shell will be used by default - shell: '' + shell: '', + + // for environment variables + env: {} // for advanced config flags please refer to https://hyperterm.org/#cfg }, diff --git a/app/session.js b/app/session.js index f6dbecab..562a3f84 100644 --- a/app/session.js +++ b/app/session.js @@ -4,6 +4,7 @@ const { exec } = require('child_process'); const defaultShell = require('default-shell'); const { getDecoratedEnv } = require('./plugins'); const { productName, version } = require('./package'); +const config = require('./config'); let spawn; try { @@ -19,6 +20,8 @@ try { const TITLE_POLL_INTERVAL = 500; +const envFromConfig = config.getConfig().env || {}; + module.exports = class Session extends EventEmitter { constructor ({ rows, cols: columns, cwd, shell }) { @@ -28,7 +31,7 @@ module.exports = class Session extends EventEmitter { TERM: 'xterm-256color', TERM_PROGRAM: productName, TERM_PROGRAM_VERSION: version - }); + }, envFromConfig); this.pty = spawn(shell || defaultShell, ['--login'], { columns,