aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/Daffm/Action/Commands.hs8
-rw-r--r--lib/Daffm/State.hs2
-rw-r--r--lib/Daffm/Types.hs1
-rw-r--r--notes.org8
4 files changed, 13 insertions, 6 deletions
diff --git a/lib/Daffm/Action/Commands.hs b/lib/Daffm/Action/Commands.hs
index 35262df..a6a55e6 100644
--- a/lib/Daffm/Action/Commands.hs
+++ b/lib/Daffm/Action/Commands.hs
@@ -6,12 +6,15 @@ module Daffm.Action.Commands where
import qualified Brick as M
import Control.Monad (forM_)
import Control.Monad.IO.Class (MonadIO (liftIO))
+import Control.Monad.State (modify)
import Daffm.Action.Cmdline
import Daffm.Action.Core
+import Daffm.Keymap (parseKeySequence)
import Daffm.Types
import Daffm.Utils (trim, trimStart)
import Data.Bifunctor (Bifunctor (second))
import Data.Char (isSpace)
+import qualified Data.Map as Map
import Data.Maybe (fromMaybe)
import qualified Data.Text as Text
import qualified Data.Text.IO as Text
@@ -48,6 +51,10 @@ parseCommand cmd = mkCmd . splitCmdArgs $ trimStart cmd
("search", term) -> Just $ CmdSearch $ trim term
("search-next", _) -> Just $ CmdSearchNext 1
("search-prev", _) -> Just $ CmdSearchNext (-1)
+ ("map", Text.break isSpace -> (keysraw, cmdraw)) -> do
+ keys <- parseKeySequence keysraw
+ cmd' <- parseCommand $ trimStart cmdraw
+ pure $ CmdKeymapSet keys cmd'
_ -> Nothing
readCommandLines' :: Text.Text -> IO [Text.Text]
@@ -88,6 +95,7 @@ processCommand CmdGoBack = goBackToParentDir
processCommand (CmdChain chain) = forM_ chain processCommand
processCommand (CmdSearch term) = setSearchTerm term >> applySearch >> nextSearchMatch
processCommand (CmdSearchNext change) = updateSearchIndex (+ change) >> nextSearchMatch
+processCommand (CmdKeymapSet keys command) = modify $ \s -> s {stateKeyMap = Map.insert keys command $ stateKeyMap s}
processCommand CmdNoop = pure ()
evaluateCommand :: Text.Text -> AppEvent ()
diff --git a/lib/Daffm/State.hs b/lib/Daffm/State.hs
index 150f34b..98b9aa9 100644
--- a/lib/Daffm/State.hs
+++ b/lib/Daffm/State.hs
@@ -10,7 +10,6 @@ import Control.Exception (try)
import Control.Monad (filterM, forM)
import Daffm.Types
import Daffm.Utils (trim)
-import Data.Either (fromRight)
import Data.List (findIndex, sortBy)
import qualified Data.Map.Strict as Map
import Data.Maybe (fromMaybe)
@@ -18,7 +17,6 @@ import qualified Data.Set as Set
import qualified Data.Text as Text
import qualified Data.Text.Zipper.Generic as Zipper
import qualified Data.Vector as Vec
-import GHC.IO.Exception (IOException (IOError))
import System.Directory (doesDirectoryExist, doesPathExist, getCurrentDirectory, getHomeDirectory, getSymbolicLinkTarget, listDirectory, makeAbsolute, setCurrentDirectory)
import System.FilePath (joinPath, takeDirectory)
import System.PosixCompat (fileExist)
diff --git a/lib/Daffm/Types.hs b/lib/Daffm/Types.hs
index e7751c4..b916c79 100644
--- a/lib/Daffm/Types.hs
+++ b/lib/Daffm/Types.hs
@@ -77,6 +77,7 @@ data Command
| CmdChain [Command]
| CmdSearch Text.Text
| CmdSearchNext Int
+ | CmdKeymapSet [Key] Command
| CmdNoop
deriving (Show, Eq)
diff --git a/notes.org b/notes.org
index 3193ada..31dac02 100644
--- a/notes.org
+++ b/notes.org
@@ -21,19 +21,19 @@
- [X] Cli arg parsing (dir arg)
- [X] Cli arg parsing (-c flag for custom config path)
- [X] handle on open (for external integrations) (opener in custom config)
+- [X] Given file name, open dir of file with cursor on file
+** Right after
- [X] chain multiple commands
- [X] Fix cmd substitution for all command args
- [X] Command: command-shell special variant of shell that evaluates output as commands
-- [X] Given file name, open dir of file with cursor on file
- [X] Config extend (extend = true will extend config.toml)
- [X] Finish nvim integration
- [X] Command: search, search-next, search-prev
- [X] cd into dir symlinks
-- [ ] Command: bind
-** Right after
+- [X] Command: map
+- [ ] theme from config
- [ ] cmdline tab completion
- [ ] Allow escaping % in commands
-- [ ] theme from config
- [ ] Cmdline history
- [ ] Store last directory path (for auto cd in shell)
- [ ] Store selections path (for copy/move/paste across instances)