Revert "add "with" command"
[diohsc.git] / Alias.hs
blobea45a263b3017f834cdd64c9e7866c8cee3e0bd6
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 = 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