@@ -152,8 +152,10 @@ import Config (
152152 Config (.. ),
153153 HookSet (.. ),
154154 HooksConfig (.. ),
155+ Shortcut (.. ),
155156 addHookFilesToConfig ,
156157 )
158+ import Data.Map.Strict qualified as Map
157159import Control.Arrow ((>>>) )
158160import Hooks (executeHooks , formatHookResult )
159161import ImportExport (
@@ -385,6 +387,8 @@ data Command
385387 | Gui
386388 | UlidToUtc Text
387389 | ExternalCommand Text (Maybe [Text ])
390+ | AddCustomShortcut Shortcut [Text ]
391+ -- ^ Custom shortcut command from config
388392 deriving (Show , Eq )
389393
390394
@@ -448,6 +452,20 @@ getCommand (alias, commandName) =
448452 (progDesc $ T. unpack $ alias <> " -> " <> commandName)
449453
450454
455+ -- | Create a parser for a custom shortcut from config
456+ getShortcutCommand :: (Text , Shortcut ) -> Mod CommandFields Command
457+ getShortcutCommand (cmdName, shortcut) =
458+ command (T. unpack cmdName) $
459+ info
460+ (AddCustomShortcut shortcut <$> some (strArgument
461+ (metavar " BODY" <> help " Body of the task" )))
462+ (progDesc $ T. unpack $ description)
463+ where
464+ description = case shortcut. prefix of
465+ Just pfx -> pfx <> " something (custom shortcut)"
466+ Nothing -> " Add task with +" <> shortcut. tag <> " tag (custom shortcut)"
467+
468+
451469toParserInfo :: Parser a -> Text -> ParserInfo a
452470toParserInfo parser description =
453471 info parser (fullDesc <> progDesc (T. unpack description))
@@ -472,6 +490,7 @@ idsVar =
472490-- | Help Sections
473491basic_sec
474492 , shortcut_sec
493+ , custom_shortcut_sec
475494 , list_sec
476495 , vis_sec
477496 , i_o_sec
@@ -482,6 +501,7 @@ basic_sec
482501 (Text , Text )
483502basic_sec = (" {{basic_sec}}" , " Basic Commands" )
484503shortcut_sec = (" {{shortcut_sec}}" , " Shortcuts to Add a Task" )
504+ custom_shortcut_sec = (" {{custom_shortcut_sec}}" , " Custom Shortcuts" )
485505list_sec = (" {{list_sec}}" , " List Commands" )
486506vis_sec = (" {{vis_sec}}" , " Visualizations" )
487507i_o_sec = (" {{i_o_sec}}" , " I/O Commands" )
@@ -730,6 +750,16 @@ commandParser conf =
730750 " Ship an item to someone" )
731751 )
732752
753+ -- Custom shortcuts from config (only show section if there are shortcuts)
754+ <|> (if null (Map. toList conf. shortcuts)
755+ then P. empty
756+ else hsubparser
757+ ( metavar (T. unpack $ snd custom_shortcut_sec)
758+ <> commandGroup (T. unpack $ fst custom_shortcut_sec)
759+ <> foldMap getShortcutCommand (Map. toList conf. shortcuts)
760+ )
761+ )
762+
733763 <|> hsubparser
734764 ( metavar (T. unpack $ snd list_sec)
735765 <> commandGroup (T. unpack $ fst list_sec)
@@ -1158,6 +1188,7 @@ helpReplacements :: Config -> [(Text, Doc AnsiStyle)]
11581188helpReplacements conf =
11591189 [ basic_sec
11601190 , shortcut_sec
1191+ , custom_shortcut_sec
11611192 , list_sec
11621193 , vis_sec
11631194 , i_o_sec
@@ -1340,6 +1371,14 @@ executeCLiCommand config now connection progName args availableLinesMb = do
13401371 AddSell bodyWords -> addTaskC $ [" Sell" ] <> bodyWords <> [" +sell" ]
13411372 AddPay bodyWords -> addTaskC $ [" Pay" ] <> bodyWords <> [" +pay" ]
13421373 AddShip bodyWords -> addTaskC $ [" Ship" ] <> bodyWords <> [" +ship" ]
1374+ AddCustomShortcut shortcut bodyWords ->
1375+ let
1376+ prefixWords = case shortcut. prefix of
1377+ Just pfx -> [pfx]
1378+ Nothing -> []
1379+ tagWord = " +" <> shortcut. tag
1380+ in
1381+ addTaskC $ prefixWords <> bodyWords <> [tagWord]
13431382 LogTask bodyWords -> logTask conf connection bodyWords
13441383 EnterTask -> enterTask conf connection
13451384 ReadyOn datetime ids -> setReadyUtc conf connection datetime ids
0 commit comments