Created
May 13, 2011 17:26
-
-
Save nakamuray/970943 to your computer and use it in GitHub Desktop.
フォーカスがあたっているターミナル上のシェルの CWD で新しくターミナルを開く XMonad 用関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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