make iconv disableable on unix
[diohsc.git] / Alias.hs
blob369d9c2a33a55dbf198723bafa72097dafb79303
1 -- This file is part of Diohsc
2 -- Copyright (C) 2020 Martin Bays <mbays@sdf.org>
3 --
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.
7 --
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/.
11 {-# LANGUAGE Safe #-}
13 module Alias where
15 import Data.Bifunctor (second)
16 import Data.List (isPrefixOf)
17 import Safe (headMay)
19 import CommandLine
21 data Alias = Alias String CommandLine
22 deriving (Eq,Ord,Show)
24 type Aliases = [(String,Alias)]
26 emptyAliases :: Aliases
27 emptyAliases = []
29 defaultAliases :: Aliases
30 defaultAliases = second aliasOf <$>
31 [ ("back", "<") , ("forward", ">") , ("next", "~") ]
32 where aliasOf s = case parseCommandLine s of
33 Right cl -> Alias s cl
34 Left _ -> error "BUG: Failed to parse command for default alias."
36 lookupAlias :: String -> Aliases -> Maybe Alias
37 lookupAlias s aliases =
38 headMay [ alias | (a,alias) <- aliases, s `isPrefixOf` a ]
40 insertAlias :: String -> Alias -> Aliases -> Aliases
41 insertAlias a alias = (++ [(a, alias)])
43 deleteAlias :: String -> Aliases -> Aliases
44 deleteAlias a = filter $ (/= a) . fst