diff options
Diffstat (limited to '')
| -rw-r--r-- | lib/Daffm/Action/Core.hs | 15 | ||||
| -rw-r--r-- | lib/Daffm/Args.hs | 2 | ||||
| -rw-r--r-- | notes.org | 7 |
3 files changed, 15 insertions, 9 deletions
diff --git a/lib/Daffm/Action/Core.hs b/lib/Daffm/Action/Core.hs index dc68c5d..85f861a 100644 --- a/lib/Daffm/Action/Core.hs +++ b/lib/Daffm/Action/Core.hs @@ -10,11 +10,13 @@ import Control.Monad (void) import Control.Monad.State (MonadIO (liftIO), MonadState, get, gets, modify, put) import Daffm.State import Daffm.Types (AppEvent, AppState (..), FileInfo (..), FilePathText, FileType (..)) +import qualified Data.Map as Map import Data.Maybe (fromMaybe) import qualified Data.Set as Set import qualified Data.Text as Text import qualified Data.Vector as Vec import System.Directory (getHomeDirectory) +import System.Environment (getEnvironment) import qualified System.Exit as Proc import System.FilePath (takeDirectory) import qualified System.Process as Proc @@ -54,7 +56,7 @@ openSelectedFile = do cmdSubstitutions :: Text.Text -> AppEvent Text.Text cmdSubstitutions cmd = gets (`substitute` cmd) where - escape = (\s -> "'" <> s <> "'") . Text.replace "'" "\\'" + escape = (\s -> "'" <> s <> "'") . Text.replace "'" "'\\''" substitute (AppState {stateFiles, stateCwd, stateFileSelections}) = Text.replace "%" (escape cursorFile) . Text.replace "%d" (escape stateCwd) @@ -72,18 +74,19 @@ cmdSubstitutions cmd = gets (`substitute` cmd) -- When exit code is non-zero, it will print it and prompt for key press regardless of waitForKey suspendAndRunShellCommand :: Bool -> Text.Text -> AppEvent () suspendAndRunShellCommand waitForKey cmd = do - suspendAndResume' $ - shellCommand (Text.unpack cmd) >>= \case + suspendAndResume' $ do + shellCommand (Text.unpack cmd) Map.empty >>= \case Proc.ExitFailure code -> do putStrLn $ "Process exited with " <> show code putStrLn "Press any key to continue" >> void getChar _ | waitForKey -> putStrLn "Press any key to continue" >> void getChar _ -> pure () -shellCommand :: String -> IO Proc.ExitCode -shellCommand cmd = do +shellCommand :: String -> Map.Map String String -> IO Proc.ExitCode +shellCommand cmd env = do + currentEnv <- getEnvironment Proc.withCreateProcess - (Proc.shell cmd) {Proc.delegate_ctlc = True} + (Proc.shell cmd) {Proc.delegate_ctlc = True, Proc.env = Just $ currentEnv ++ Map.toList env} $ \_ _ _ p -> Proc.waitForProcess p currentFile :: AppEvent (Maybe FileInfo) diff --git a/lib/Daffm/Args.hs b/lib/Daffm/Args.hs index aeaead7..1b81827 100644 --- a/lib/Daffm/Args.hs +++ b/lib/Daffm/Args.hs @@ -9,7 +9,7 @@ parseArgs rawArgs = case parsedArgs of Left e -> throwIO $ userError e Right v -> pure v where - parsedArgs = parse rawArgs (Args {argsDirOrFile = Nothing, argsConfigFile = Nothing, argsHelp = False}) + parsedArgs = parse rawArgs $ Args {argsDirOrFile = Nothing, argsConfigFile = Nothing, argsHelp = False} parse :: [String] -> Args -> Either String Args parse [] args = Right args parse ("-h" : _) args = Right $ args {argsHelp = True} @@ -1,14 +1,17 @@ - [X] commands: move cursor: move +1, move -1, move 5, move $, move 0 - [X] rename command-shell to evaluate - [X] Allow recursive config extends (@A -> @B -> @C) -- [ ] allow escaping % in commands -- [ ] fix problems with substitutions (maybe switch to env vars?) - [ ] custom commands +- [X] fix problems with substitutions (maybe switch to env vars?) +- [ ] allow escaping % in commands +- [ ] allow updating selection list (:selection-add, :selection-delete) - [ ] cmdline autocompletion - [ ] handle permissions errors - [ ] Use ls for file listing respecting ansi colors? - [ ] Generalize cd/opener/back? +- [ ] Show error messages (invalid commands/shell errors) ** Later +- [ ] cross instance selections? (just override keys?) - [ ] Show last cmd in cmdline - [ ] preserve back directory when going inside symlink to directories - [ ] cmdline history |
