diff --git a/app/lib/actions/sessions.js b/app/lib/actions/sessions.js index eab2cc05..cbc7dd32 100644 --- a/app/lib/actions/sessions.js +++ b/app/lib/actions/sessions.js @@ -19,7 +19,7 @@ import { SESSION_SET_PROCESS_TITLE } from '../constants/sessions'; -export function addSession (uid, shell) { +export function addSession (uid, shell, pid) { return (dispatch, getState) => { const { sessions } = getState(); @@ -32,7 +32,8 @@ export function addSession (uid, shell) { dispatch({ type: SESSION_ADD, uid, - shell + shell, + pid }); }; } @@ -40,12 +41,11 @@ export function addSession (uid, shell) { export function requestSession (uid) { return (dispatch, getState) => { const { ui } = getState(); - const cols = ui.cols; - const rows = ui.rows; + const { cols, rows, cwd } = ui; dispatch({ type: SESSION_REQUEST, effect: () => { - rpc.emit('new', { cols, rows }); + rpc.emit('new', { cols, rows, cwd }); } }); }; diff --git a/app/lib/index.js b/app/lib/index.js index 924d301b..e95b730b 100644 --- a/app/lib/index.js +++ b/app/lib/index.js @@ -43,8 +43,8 @@ rpc.on('ready', () => { store_.dispatch(init()); }); -rpc.on('session add', ({ uid, shell }) => { - store_.dispatch(sessionActions.addSession(uid, shell)); +rpc.on('session add', ({ uid, shell, pid }) => { + store_.dispatch(sessionActions.addSession(uid, shell, pid)); }); rpc.on('session data', ({ uid, data }) => { diff --git a/app/lib/reducers/sessions.js b/app/lib/reducers/sessions.js index ae5d9079..84ad585a 100644 --- a/app/lib/reducers/sessions.js +++ b/app/lib/reducers/sessions.js @@ -26,7 +26,8 @@ function Session (obj) { write: null, url: null, cleared: false, - shell: '' + shell: '', + pid: null }).merge(obj); } @@ -42,7 +43,8 @@ const reducer = (state = initialState, action) => { case SESSION_ADD: return state.setIn(['sessions', action.uid], Session({ uid: action.uid, - shell: action.shell.split('/').pop() + shell: action.shell.split('/').pop(), + pid: action.pid })); case SESSION_URL_SET: diff --git a/index.js b/index.js index 6a540181..a07d46cc 100644 --- a/index.js +++ b/index.js @@ -80,12 +80,13 @@ app.on('ready', () => { } }); - rpc.on('new', ({ rows = 40, cols = 100 }) => { - initSession({ rows, cols }, (uid, session) => { + rpc.on('new', ({ rows = 40, cols = 100, cwd = process.env.HOME }) => { + initSession({ rows, cols, cwd }, (uid, session) => { sessions.set(uid, session); rpc.emit('session add', { uid, - shell: session.shell + shell: session.shell, + pid: session.pty.pid }); session.on('data', (data) => { diff --git a/session.js b/session.js index d6913044..81f17d99 100644 --- a/session.js +++ b/session.js @@ -18,12 +18,12 @@ const TITLE_POLL_INTERVAL = 500; module.exports = class Session extends EventEmitter { - constructor ({ rows, cols: columns }) { + constructor ({ rows, cols: columns, cwd }) { super(); this.pty = spawn(defaultShell, ['--login'], { columns, rows, - cwd: process.env.HOME, + cwd, env: Object.assign({}, process.env, { TERM: 'xterm-256color' })