aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Daffm/Action/Commands.hs20
-rw-r--r--lib/Daffm/Action/Core.hs8
-rw-r--r--lib/Daffm/Configuration.hs10
-rw-r--r--lib/Daffm/State.hs2
-rw-r--r--lib/Daffm/Types.hs9
-rw-r--r--notes.org3
6 files changed, 33 insertions, 19 deletions
diff --git a/lib/Daffm/Action/Commands.hs b/lib/Daffm/Action/Commands.hs
index a963191..9a90f93 100644
--- a/lib/Daffm/Action/Commands.hs
+++ b/lib/Daffm/Action/Commands.hs
@@ -42,15 +42,17 @@ parseCommand cmd = mkCmd . splitCmdArgs $ trimStart cmd
("shell", cmd') -> Just $ CmdShell False cmd'
("eval", cmd') -> Just $ CmdCommandShell cmd'
("back", _) -> Just CmdGoBack
- ("open", _) -> Just CmdOpenSelection
+ ("open", _) -> Just CmdSelectionOpen
("reload", _) -> Just CmdReload
("cd", dir) -> Just $ CmdChangeDir dir
("noop", _) -> Just CmdNoop
("cmdline-enter", _) -> Just CmdEnterCmdline
("cmdline-leave", _) -> Just CmdLeaveCmdline
("cmdline-set", txt) -> Just $ CmdSetCmdline txt
- ("selection-toggle", _) -> Just CmdToggleSelection
- ("selection-clear", _) -> Just CmdClearSelection
+ ("selection-toggle", _) -> Just CmdSelectionToggle
+ ("selection-clear", _) -> Just CmdSelectionClear
+ ("selection-add", file) -> Just $ CmdSelectionAdd file
+ ("selection-remove", file) -> Just $ CmdSelectionRemove file
("search", term) -> Just $ CmdSearch $ trim term
("search-next", _) -> Just $ CmdSearchNext 1
("search-prev", _) -> Just $ CmdSearchNext (-1)
@@ -98,11 +100,13 @@ processCommand (CmdSetCmdline txt) args =
enterCmdline >> cmdSubstitutions (argSubst args txt) >>= setCmdlineText
processCommand CmdEnterCmdline _args = enterCmdline
processCommand CmdLeaveCmdline _args = leaveCmdline
-processCommand CmdOpenSelection _args = openSelectedFile
+processCommand CmdSelectionOpen _args = openSelectedFile
processCommand (CmdChangeDir dir) args = cmdSubstitutions (argSubst args dir) >>= changeDir
processCommand CmdReload _args = reloadDir
-processCommand CmdToggleSelection _args = toggleCurrentFileSelection
-processCommand CmdClearSelection _args = clearFileSelections
+processCommand CmdSelectionToggle _args = toggleCurrentFileSelection
+processCommand CmdSelectionClear _args = clearFileSelections
+processCommand (CmdSelectionAdd file) _args = addFileSelection $ trim file -- TODO: Subst
+processCommand (CmdSelectionRemove file) _args = removeFileSelection $ trim file -- TODO: Subst
processCommand CmdGoBack _ = goBackToParentDir
processCommand (CmdChain chain) args = forM_ chain (`processCommand` args)
processCommand (CmdSearch term) _ = setSearchTerm term >> applySearch >> nextSearchMatch
@@ -123,12 +127,12 @@ processCommand (CmdCustom cmd args) _ = do
myCmd <- gets $ Map.lookup cmd . stateCustomCommands
case myCmd of
Just command -> processCommand command args
- Nothing -> modify (\st -> st { stateMessage = Just $ "Invalid command " <> cmd })
+ Nothing -> modify (\st -> st {stateMessage = Just $ "Invalid command " <> cmd})
processCommand CmdNoop _ = pure ()
evaluateCommand :: Text.Text -> AppEvent ()
evaluateCommand cmdtxt = do
- modify (\st -> st { stateMessage = Nothing })
+ modify (\st -> st {stateMessage = Nothing})
case parseCommand cmdtxt of
Just cmd -> processCommand cmd ""
Nothing -> pure ()
diff --git a/lib/Daffm/Action/Core.hs b/lib/Daffm/Action/Core.hs
index 85f861a..ba50638 100644
--- a/lib/Daffm/Action/Core.hs
+++ b/lib/Daffm/Action/Core.hs
@@ -99,6 +99,14 @@ toggleCurrentFileSelection = do
Nothing -> pure ()
moveCurrent 1
+addFileSelection :: FilePathText -> AppEvent ()
+addFileSelection path = do
+ modify $ \st -> st {stateFileSelections = Set.insert path . stateFileSelections $ st}
+
+removeFileSelection :: FilePathText -> AppEvent ()
+removeFileSelection path = do
+ modify $ \st -> st {stateFileSelections = Set.delete path . stateFileSelections $ st}
+
clearFileSelections :: AppEvent ()
clearFileSelections =
modify $ \st -> st {stateFileSelections = Set.empty}
diff --git a/lib/Daffm/Configuration.hs b/lib/Daffm/Configuration.hs
index ee8f88e..e0ed5ad 100644
--- a/lib/Daffm/Configuration.hs
+++ b/lib/Daffm/Configuration.hs
@@ -40,13 +40,13 @@ defaultKeymaps =
([K.KChar 'n'], CmdSearchNext 1),
([K.KChar 'N'], CmdSearchNext (-1)),
([K.KChar ':'], CmdEnterCmdline),
- ([K.KChar 'l'], CmdOpenSelection),
+ ([K.KChar 'l'], CmdSelectionOpen),
([K.KChar 'h'], CmdGoBack),
- ([K.KEnter], CmdOpenSelection),
+ ([K.KEnter], CmdSelectionOpen),
([K.KBS], CmdGoBack),
- ([K.KChar 'v'], CmdToggleSelection),
- ([K.KChar '\t'], CmdToggleSelection),
- ([K.KChar 'C'], CmdClearSelection),
+ ([K.KChar 'v'], CmdSelectionToggle),
+ ([K.KChar '\t'], CmdSelectionToggle),
+ ([K.KChar 'C'], CmdSelectionClear),
([K.KChar '~'], CmdChangeDir "~"),
([K.KChar '$'], CmdShell False "$SHELL"),
([K.KChar 'g', K.KChar 'x'], CmdShell False "!xdg-open % >/dev/null 2>&1"),
diff --git a/lib/Daffm/State.hs b/lib/Daffm/State.hs
index 902b6c6..1334327 100644
--- a/lib/Daffm/State.hs
+++ b/lib/Daffm/State.hs
@@ -17,7 +17,7 @@ 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 System.Directory (doesDirectoryExist, doesPathExist, getCurrentDirectory, getHomeDirectory, getPermissions, getSymbolicLinkTarget, listDirectory, makeAbsolute, readable, setCurrentDirectory)
+import System.Directory (doesPathExist, getCurrentDirectory, getHomeDirectory, getPermissions, getSymbolicLinkTarget, listDirectory, makeAbsolute, readable, setCurrentDirectory)
import System.FilePath (joinPath, takeDirectory)
import System.PosixCompat (fileExist)
import qualified System.PosixCompat as Posix
diff --git a/lib/Daffm/Types.hs b/lib/Daffm/Types.hs
index a26b0ef..0b22816 100644
--- a/lib/Daffm/Types.hs
+++ b/lib/Daffm/Types.hs
@@ -74,11 +74,13 @@ data Command
| CmdSetCmdline Text.Text
| CmdEnterCmdline
| CmdLeaveCmdline
- | CmdOpenSelection
+ | CmdSelectionOpen
| CmdChangeDir Text.Text
| CmdReload
- | CmdToggleSelection
- | CmdClearSelection
+ | CmdSelectionToggle
+ | CmdSelectionAdd Text.Text
+ | CmdSelectionRemove Text.Text
+ | CmdSelectionClear
| CmdGoBack
| CmdChain [Command]
| CmdSearch Text.Text
@@ -117,4 +119,3 @@ data Args = Args
argsHelp :: Bool
}
deriving (Show)
-
diff --git a/notes.org b/notes.org
index a45483d..ee2abb6 100644
--- a/notes.org
+++ b/notes.org
@@ -4,13 +4,14 @@
- [X] custom commands
- [X] fix problems with substitutions (maybe switch to env vars?)
- [X] handle permissions errors
+- [X] Show error messages (invalid commands/shell errors)
+- [ ] fix issue with pathExists check for ~ expansion
- [ ] allow escaping % in commands
- [ ] escape % in file paths while substituting
- [ ] allow updating selection list (:selection-add, :selection-delete)
- [ ] cmdline autocompletion
- [ ] Use ls for file listing respecting ansi colors?
- [ ] Generalize cd/opener/back?
-- [X] Show error messages (invalid commands/shell errors)
** Later
- [ ] cross instance selections? (just override keys?)
- [ ] Show last cmd in cmdline