Skip to content

Commit

Permalink
Tab titles now show cwd (vercel#2907)
Browse files Browse the repository at this point in the history
  • Loading branch information
El-Dringo-Brannde committed May 14, 2018
1 parent 9232875 commit 49ecdf8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/reducers/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
SESSION_SET_CWD
} from '../constants/sessions';

import getCWD from '../utils/fs';

const initialState = Immutable({
sessions: {},
activeUid: null
Expand Down Expand Up @@ -82,7 +84,7 @@ const reducer = (state = initialState, action) => {
{deep: true}
);
}
return state;
return state.setIn(['sessions', action.uid, 'title'], getCWD(state.sessions[action.uid].pid, action));

case SESSION_PTY_EXIT:
if (state.sessions[action.uid]) {
Expand Down
27 changes: 27 additions & 0 deletions lib/utils/fs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
FS Utility functions go here.
------
getCWD kindly taken from henrikdahl's plugin hyper statusline
https://github.com/henrikdahl/hyper-statusline/blob/master/index.js
*/

import {execSync} from 'child_process';

export default function getCWD(pid, action) {
let cwd;
if (process.platform == 'win32') {
let directoryRegex = /([a-zA-Z]+)/im;
if (action && action.data) {
let path = directoryRegex.exec(action.data);
if (path) cwd = path[0];
}
} else {
cwd = execSync(`lsof -p ${pid} | awk '$4=="cwd"' | tr -s ' ' | cut -d ' ' -f9-`, {encoding: 'utf8'});
cwd = `/${cwd
.split('/')
.pop()
.trim()}`;
}
return cwd;
}

0 comments on commit 49ecdf8

Please sign in to comment.