@@ -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,23 @@ 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 -> case shortcut. tags of
467+ [] -> " Add task (custom shortcut)"
468+ [t] -> " Add task with +" <> t <> " tag (custom shortcut)"
469+ ts -> " Add task with " <> T. intercalate " , " (fmap (" +" <> ) ts) <> " tags (custom shortcut)"
470+
471+
451472toParserInfo :: Parser a -> Text -> ParserInfo a
452473toParserInfo parser description =
453474 info parser (fullDesc <> progDesc (T. unpack description))
@@ -472,6 +493,7 @@ idsVar =
472493-- | Help Sections
473494basic_sec
474495 , shortcut_sec
496+ , custom_shortcut_sec
475497 , list_sec
476498 , vis_sec
477499 , i_o_sec
@@ -482,6 +504,7 @@ basic_sec
482504 (Text , Text )
483505basic_sec = (" {{basic_sec}}" , " Basic Commands" )
484506shortcut_sec = (" {{shortcut_sec}}" , " Shortcuts to Add a Task" )
507+ custom_shortcut_sec = (" {{custom_shortcut_sec}}" , " Custom Shortcuts" )
485508list_sec = (" {{list_sec}}" , " List Commands" )
486509vis_sec = (" {{vis_sec}}" , " Visualizations" )
487510i_o_sec = (" {{i_o_sec}}" , " I/O Commands" )
@@ -730,6 +753,16 @@ commandParser conf =
730753 " Ship an item to someone" )
731754 )
732755
756+ -- Custom shortcuts from config (only show section if there are shortcuts)
757+ <|> (if null (Map. toList conf. shortcuts)
758+ then P. empty
759+ else hsubparser
760+ ( metavar (T. unpack $ snd custom_shortcut_sec)
761+ <> commandGroup (T. unpack $ fst custom_shortcut_sec)
762+ <> foldMap getShortcutCommand (Map. toList conf. shortcuts)
763+ )
764+ )
765+
733766 <|> hsubparser
734767 ( metavar (T. unpack $ snd list_sec)
735768 <> commandGroup (T. unpack $ fst list_sec)
@@ -1158,6 +1191,7 @@ helpReplacements :: Config -> [(Text, Doc AnsiStyle)]
11581191helpReplacements conf =
11591192 [ basic_sec
11601193 , shortcut_sec
1194+ , custom_shortcut_sec
11611195 , list_sec
11621196 , vis_sec
11631197 , i_o_sec
@@ -1340,6 +1374,14 @@ executeCLiCommand config now connection progName args availableLinesMb = do
13401374 AddSell bodyWords -> addTaskC $ [" Sell" ] <> bodyWords <> [" +sell" ]
13411375 AddPay bodyWords -> addTaskC $ [" Pay" ] <> bodyWords <> [" +pay" ]
13421376 AddShip bodyWords -> addTaskC $ [" Ship" ] <> bodyWords <> [" +ship" ]
1377+ AddCustomShortcut shortcut bodyWords ->
1378+ let
1379+ prefixWords = case shortcut. prefix of
1380+ Just pfx -> [pfx]
1381+ Nothing -> []
1382+ tagWords = fmap (" +" <> ) shortcut. tags
1383+ in
1384+ addTaskC $ prefixWords <> bodyWords <> tagWords
13431385 LogTask bodyWords -> logTask conf connection bodyWords
13441386 EnterTask -> enterTask conf connection
13451387 ReadyOn datetime ids -> setReadyUtc conf connection datetime ids
0 commit comments