1 -- This file is part of Diohsc
2 -- Copyright (C) 2020 Martin Bays <mbays@sdf.org>
4 -- This program is free software: you can redistribute it and/or modify
5 -- it under the terms of version 3 of the GNU General Public License as
6 -- published by the Free Software Foundation, or any later version.
8 -- You should have received a copy of the GNU General Public License
9 -- along with this program. If not, see http://www.gnu.org/licenses/.
15 import Data
.Bifunctor
(second
)
16 import Data
.List
(isPrefixOf)
21 data Alias
= Alias
String CommandLine
22 deriving (Eq
,Ord
,Show)
24 type Aliases
= [(String,Alias
)]
26 emptyAliases
:: Aliases
29 defaultAliases
:: Aliases
30 defaultAliases
= second aliasOf
<$>
31 [ ("back", "<") , ("forward", ">") , ("next", "~") ]
32 where aliasOf s
= let Right cl
= parseCommandLine s
in Alias s cl
34 lookupAlias
:: String -> Aliases
-> Maybe Alias
35 lookupAlias s aliases
=
36 headMay
[ alias |
(a
,alias
) <- aliases
, s `
isPrefixOf` a
]
38 insertAlias
:: String -> Alias
-> Aliases
-> Aliases
39 insertAlias a alias
= (++ [(a
, alias
)])
41 deleteAlias
:: String -> Aliases
-> Aliases
42 deleteAlias a
= filter $ (/= a
) . fst