Provide hooks to open a new tab to the same directory (#174)

* provide a cwd for #4

* expose a pid for #4
This commit is contained in:
Harrison Harnisch 2016-07-16 17:41:13 -05:00 committed by Guillermo Rauch
parent ba84c12788
commit 04c0b1acff
5 changed files with 17 additions and 14 deletions

View file

@ -19,7 +19,7 @@ import {
SESSION_SET_PROCESS_TITLE SESSION_SET_PROCESS_TITLE
} from '../constants/sessions'; } from '../constants/sessions';
export function addSession (uid, shell) { export function addSession (uid, shell, pid) {
return (dispatch, getState) => { return (dispatch, getState) => {
const { sessions } = getState(); const { sessions } = getState();
@ -32,7 +32,8 @@ export function addSession (uid, shell) {
dispatch({ dispatch({
type: SESSION_ADD, type: SESSION_ADD,
uid, uid,
shell shell,
pid
}); });
}; };
} }
@ -40,12 +41,11 @@ export function addSession (uid, shell) {
export function requestSession (uid) { export function requestSession (uid) {
return (dispatch, getState) => { return (dispatch, getState) => {
const { ui } = getState(); const { ui } = getState();
const cols = ui.cols; const { cols, rows, cwd } = ui;
const rows = ui.rows;
dispatch({ dispatch({
type: SESSION_REQUEST, type: SESSION_REQUEST,
effect: () => { effect: () => {
rpc.emit('new', { cols, rows }); rpc.emit('new', { cols, rows, cwd });
} }
}); });
}; };

View file

@ -43,8 +43,8 @@ rpc.on('ready', () => {
store_.dispatch(init()); store_.dispatch(init());
}); });
rpc.on('session add', ({ uid, shell }) => { rpc.on('session add', ({ uid, shell, pid }) => {
store_.dispatch(sessionActions.addSession(uid, shell)); store_.dispatch(sessionActions.addSession(uid, shell, pid));
}); });
rpc.on('session data', ({ uid, data }) => { rpc.on('session data', ({ uid, data }) => {

View file

@ -26,7 +26,8 @@ function Session (obj) {
write: null, write: null,
url: null, url: null,
cleared: false, cleared: false,
shell: '' shell: '',
pid: null
}).merge(obj); }).merge(obj);
} }
@ -42,7 +43,8 @@ const reducer = (state = initialState, action) => {
case SESSION_ADD: case SESSION_ADD:
return state.setIn(['sessions', action.uid], Session({ return state.setIn(['sessions', action.uid], Session({
uid: action.uid, uid: action.uid,
shell: action.shell.split('/').pop() shell: action.shell.split('/').pop(),
pid: action.pid
})); }));
case SESSION_URL_SET: case SESSION_URL_SET:

View file

@ -80,12 +80,13 @@ app.on('ready', () => {
} }
}); });
rpc.on('new', ({ rows = 40, cols = 100 }) => { rpc.on('new', ({ rows = 40, cols = 100, cwd = process.env.HOME }) => {
initSession({ rows, cols }, (uid, session) => { initSession({ rows, cols, cwd }, (uid, session) => {
sessions.set(uid, session); sessions.set(uid, session);
rpc.emit('session add', { rpc.emit('session add', {
uid, uid,
shell: session.shell shell: session.shell,
pid: session.pty.pid
}); });
session.on('data', (data) => { session.on('data', (data) => {

View file

@ -18,12 +18,12 @@ const TITLE_POLL_INTERVAL = 500;
module.exports = class Session extends EventEmitter { module.exports = class Session extends EventEmitter {
constructor ({ rows, cols: columns }) { constructor ({ rows, cols: columns, cwd }) {
super(); super();
this.pty = spawn(defaultShell, ['--login'], { this.pty = spawn(defaultShell, ['--login'], {
columns, columns,
rows, rows,
cwd: process.env.HOME, cwd,
env: Object.assign({}, process.env, { env: Object.assign({}, process.env, {
TERM: 'xterm-256color' TERM: 'xterm-256color'
}) })