implement dynamic changing of working directory

This commit is contained in:
Maximilian Keßler 2022-07-19 20:31:26 +02:00
parent 6efab03456
commit cfbc283c3a

View file

@ -6,6 +6,8 @@ module XMonad.Custom.TopicSpace (
, currentTopicConfig
, goto
, spawnInTopicDir
, setTopicDir
, promptSetTopicDir
) where
@ -43,12 +45,14 @@ module XMonad.Custom.TopicSpace (
--
--
-- import qualified Data.Map.Strict as M
import Data.Map
import qualified XMonad.Util.ExtensibleState as XS
-- import qualified XMonad.StackSet as W
import qualified XMonad.StackSet as W
import XMonad
import XMonad.Actions.TopicSpace
import XMonad.Prompt
import XMonad.Prompt.Workspace
-- | An alias for topicNames.
@ -84,15 +88,19 @@ instance ExtensionClass StoreTopicConfig where
topicConfig :: StoreTopicConfig -> TopicConfig
topicConfig (StoreTopicConfig tc) = tc
-- | Put initial topic Config into X state at startup
-- Add this to the XConfig startupHook
topicStartupHook :: TopicConfig -> X ()
topicStartupHook = XS.put . StoreTopicConfig
-- | Update the value of the topic config in the X state
updateTopicConfig :: TopicConfig -> X ()
updateTopicConfig = XS.put . StoreTopicConfig
-- | Retrieve the current topic config from the X state
currentTopicConfig :: X TopicConfig
currentTopicConfig = fmap topicConfig XS.get
-- | Put initial topic Config into X state at startup
-- Add this to the XConfig startupHook
topicStartupHook :: TopicConfig -> X ()
topicStartupHook = updateTopicConfig
-------------------------------------------
-- | These are the real utilities that we aimed for
@ -112,3 +120,16 @@ spawnInTopicDir cmd = do
tc <- currentTopicConfig
dir <- currentTopicDir tc
spawn $ "cd " ++ dir ++ "; " ++ cmd
-- | Set the working directory of the current topic
setTopicDir :: Dir -> X ()
setTopicDir dir = do
ws <- gets (W.currentTag . windowset)
tc <- currentTopicConfig
updateTopicConfig tc {
topicDirs = insert ws dir $ topicDirs tc
}
-- | Prompt for the new working directory
promptSetTopicDir :: XPConfig -> X ()
promptSetTopicDir xpc = workspacePrompt xpc setTopicDir