Skip to content

Instantly share code, notes, and snippets.

@nakamuray
Created May 13, 2011 17:26
Show Gist options
  • Save nakamuray/970943 to your computer and use it in GitHub Desktop.
Save nakamuray/970943 to your computer and use it in GitHub Desktop.
フォーカスがあたっているターミナル上のシェルの CWD で新しくターミナルを開く XMonad 用関数
getWindowPID :: Window -> X (Maybe Int)
getWindowPID w = withDisplay $ \dpy -> do
atom <- getAtom "_NET_WM_PID"
ret <- io $ getWindowProperty32 dpy atom w
case ret of
Just (pid:_) -> return $ Just $ fromIntegral pid
_ -> return Nothing
spawnTerminalInCWD :: X ()
spawnTerminalInCWD = do
XConf { config = XConfig { terminal = term } } <- ask
withWindowSet $ \ws -> do
case W.peek ws of
Just w -> do
ret <- getWindowPID w
case ret of
Just pid -> spawn $ "cwd=$(readlink /proc/$(ps --ppid " ++ show pid ++ " ho pid | head -n 1 | tr -d ' ')/cwd); \
\cd \"${cwd}\"; \
\exec " ++ term
Nothing -> spawn term
Nothing ->
spawn term
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment