diff --git a/lib/reducers/sessions.js b/lib/reducers/sessions.js index d012dcb7d0ec..d8322a425e00 100644 --- a/lib/reducers/sessions.js +++ b/lib/reducers/sessions.js @@ -14,6 +14,8 @@ import { SESSION_SET_CWD } from '../constants/sessions'; +import getCWD from '../utils/fs'; + const initialState = Immutable({ sessions: {}, activeUid: null @@ -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]) { diff --git a/lib/utils/fs.js b/lib/utils/fs.js new file mode 100644 index 000000000000..5125088f655d --- /dev/null +++ b/lib/utils/fs.js @@ -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; +}