summaryrefslogtreecommitdiff
path: root/Pancake
diff options
context:
space:
mode:
Diffstat (limited to 'Pancake')
-rw-r--r--Pancake/Command.hs12
-rw-r--r--Pancake/Configuration.hs13
2 files changed, 17 insertions, 8 deletions
diff --git a/Pancake/Command.hs b/Pancake/Command.hs
index 4c34a19..52ace06 100644
--- a/Pancake/Command.hs
+++ b/Pancake/Command.hs
@@ -59,7 +59,7 @@ data Command = Quit
| Show Int
| ShowCurrent
| Shortcut String String
- | ReloadConfig
+ | LoadConfig (Maybe FilePath)
| SetWidth (Maybe Int)
| Redisplay
deriving (Show, Eq)
@@ -75,7 +75,6 @@ basicCommand = choice . map (\(s, c) -> try (string s <* eof) *> pure c) $
, ("[", Back)
, ("]", Forward)
, (",", GoTo Nothing RCurrent)
- , ("reload config", ReloadConfig)
, ("help", Help)
, ("?", ShowCurrent)
, ("redisplay", Redisplay)
@@ -151,7 +150,13 @@ pNat = read <$> many1 digit
-- | 'SetWidth' command parser.
setWidth :: Parser Command
setWidth = string "set width"
- *> (SetWidth <$> optionMaybe (spaces *> pNat))
+ *> (SetWidth <$> optionMaybe (space *> pNat))
+ <* eof
+
+-- | 'LoadConfig' command parser.
+loadConf :: Parser Command
+loadConf = string "load config"
+ *> (LoadConfig <$> optionMaybe (space *> many1 anyChar))
<* eof
-- | Command parser.
@@ -166,5 +171,6 @@ command c =
, saveCurrent <?> "save current"
, save <?> "save"
, setWidth <?> "set width"
+ , loadConf <?> "load config"
, goTo <?> "follow uri"
])
diff --git a/Pancake/Configuration.hs b/Pancake/Configuration.hs
index ae42f65..772725e 100644
--- a/Pancake/Configuration.hs
+++ b/Pancake/Configuration.hs
@@ -116,11 +116,14 @@ instance Default Config where
"-w \"\n-pancake-\nuri: %{url_effective}\ntype: %{content_type}\n\" "
-- | Loads configuration from an XDG config directory.
-loadConfig :: MonadIO m => m Config
-loadConfig = liftIO $ do
- dir <- getXdgDirectory XdgConfig "pancake"
- createDirectoryIfMissing True dir
- let configPath = dir </> "config.yaml"
+loadConfig :: MonadIO m => Maybe FilePath -> m Config
+loadConfig mp = liftIO $ do
+ configPath <- case mp of
+ Nothing -> do
+ dir <- getXdgDirectory XdgConfig "pancake"
+ createDirectoryIfMissing True dir
+ pure $ dir </> "config.yaml"
+ Just p -> pure p
exists <- doesFileExist configPath
if exists
then do