aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/Daffm/Action/Commands.hs32
-rw-r--r--lib/Daffm/Types.hs1
-rw-r--r--notes.org15
3 files changed, 39 insertions, 9 deletions
diff --git a/lib/Daffm/Action/Commands.hs b/lib/Daffm/Action/Commands.hs
index a5116eb..98fec9a 100644
--- a/lib/Daffm/Action/Commands.hs
+++ b/lib/Daffm/Action/Commands.hs
@@ -5,13 +5,19 @@ module Daffm.Action.Commands where
import qualified Brick as M
import Control.Monad (forM_)
+import Control.Monad.IO.Class (MonadIO (liftIO))
import Daffm.Action.Cmdline
import Daffm.Action.Core
import Daffm.Types
import Daffm.Utils (trimStart)
import Data.Bifunctor (Bifunctor (second))
import Data.Char (isSpace)
+import Data.Maybe (fromMaybe)
import qualified Data.Text as Text
+import qualified Data.Text.IO as Text
+import qualified GHC.IO.Handle.Text as Proc
+import System.Process (readProcessWithExitCode)
+import qualified System.Process as Proc
runCmdline :: AppEvent ()
runCmdline = do
@@ -30,6 +36,7 @@ parseCommand cmd = mkCmd . splitCmdArgs $ trimStart cmd
("quit", _) -> Just CmdQuit
("shell!", cmd') -> Just $ CmdShell True cmd'
("shell", cmd') -> Just $ CmdShell False cmd'
+ ("command-shell", cmd') -> Just $ CmdCommandShell cmd'
("back", _) -> Just CmdGoBack
("open", _) -> Just CmdOpenSelection
("reload", _) -> Just CmdReload
@@ -42,16 +49,37 @@ parseCommand cmd = mkCmd . splitCmdArgs $ trimStart cmd
("selection-clear", _) -> Just CmdClearSelection
_ -> Nothing
+readCommandLines' :: Text.Text -> IO [Text.Text]
+readCommandLines' cmd = do
+ Proc.withCreateProcess
+ (Proc.shell $ Text.unpack cmd)
+ { Proc.delegate_ctlc = True,
+ Proc.std_in = Proc.NoStream,
+ Proc.std_out = Proc.CreatePipe,
+ Proc.std_err = Proc.NoStream
+ }
+ $ \_ stdout _ p -> do
+ _ <- Proc.waitForProcess p
+ Text.lines <$> maybe (pure "") Text.hGetContents stdout
+
processCommand :: Command -> AppEvent ()
processCommand (CmdShell waitForKey cmd) = do
cmdSubstitutions cmd >>= suspendAndRunShellCommand waitForKey
reloadDir
+processCommand (CmdCommandShell cmd) = do
+ stdout <- cmdSubstitutions cmd >>= liftIO . readCommandLines'
+ forM_ stdout runIfCmd
+ reloadDir
+ where
+ runIfCmd (Text.stripPrefix "<daffm>" -> Just cmd') =
+ processCommand $ fromMaybe CmdNoop (parseCommand cmd')
+ runIfCmd _ = pure ()
processCommand CmdQuit = M.halt
-processCommand (CmdSetCmdline txt) = enterCmdline >> setCmdlineText txt
+processCommand (CmdSetCmdline txt) = enterCmdline >> cmdSubstitutions txt >>= setCmdlineText
processCommand CmdEnterCmdline = enterCmdline
processCommand CmdLeaveCmdline = leaveCmdline
processCommand CmdOpenSelection = openSelectedFile
-processCommand (CmdChangeDir dir) = changeDir dir
+processCommand (CmdChangeDir dir) = cmdSubstitutions dir >>= changeDir
processCommand CmdReload = reloadDir
processCommand CmdToggleSelection = toggleCurrentFileSelection
processCommand CmdClearSelection = clearFileSelections
diff --git a/lib/Daffm/Types.hs b/lib/Daffm/Types.hs
index 197ab63..5133c2b 100644
--- a/lib/Daffm/Types.hs
+++ b/lib/Daffm/Types.hs
@@ -55,6 +55,7 @@ data KeyMatchResult = MatchSuccess Command | MatchPartial | MatchFailure
data Command
= CmdShell Bool Text.Text
+ | CmdCommandShell Text.Text
| CmdQuit
| CmdSetCmdline Text.Text
| CmdEnterCmdline
diff --git a/notes.org b/notes.org
index 3bfd14c..89820e3 100644
--- a/notes.org
+++ b/notes.org
@@ -22,24 +22,25 @@
- [X] Cli arg parsing (-c flag for custom config path)
- [X] handle on open (for external integrations) (opener in custom config)
- [X] chain multiple commands
-- [ ] Store last directory path
-- [ ] Store selections path
+- [X] Fix cmd substitution for all command args
+- [X] Command: command-shell special variant of shell that evaluates output as commands
+- [ ] Given file name, open dir of file with cursor on file
+- [ ] Store last directory path (for auto cd in shell)
+- [ ] Store selections path (for copy/move/paste across instances)
- [ ] Command: search, search-next, search-prev
** Right after
-- [ ] copy/move/paste selections across instances
- - user-land solution (write selections to file and read from second instance)
- - socket
-- [ ] think about nvim integration (server + send back)
-- [ ] Fix keymap evaluation: If v is bound, it doesnt evaluate vd since v was found
- [ ] Cmdline history
- [ ] Command: pipe (think about this) (pipe selection file names/file contents)
- [ ] Allow escaping % in commands
- [ ] Rethink % substituions
- [ ] theme from config
- [ ] cd into dir symlinks
+- [ ] Fix keymap evaluation? (If vd is bound, it doesnt evaluate a v binding)
+- [ ] Config extend (extend = true will extend config.toml)
** Later
- [ ] cmdline tab completion
- [ ] Allow escaping % in commands
- [ ] watch for changes
- [ ] bind command: define keybindings
- [ ] some caching for file list?
+- [ ] Command aliases