added getenv with alias $
This commit is contained in:
parent
9e4bf60eac
commit
4064004e09
1 changed files with 11 additions and 4 deletions
|
@ -11,7 +11,6 @@ import qualified Data.Map.Strict as Map
|
||||||
import qualified Data.Text as Text
|
import qualified Data.Text as Text
|
||||||
import GHC.IO.Handle (hGetContents)
|
import GHC.IO.Handle (hGetContents)
|
||||||
import Lish.Types
|
import Lish.Types
|
||||||
import qualified Prelude as Prelude
|
|
||||||
import Protolude
|
import Protolude
|
||||||
import System.Environment (setEnv)
|
import System.Environment (setEnv)
|
||||||
|
|
||||||
|
@ -51,6 +50,12 @@ export ((Atom name):v@(Str s):[]) = do
|
||||||
return v
|
return v
|
||||||
export _ = return Void
|
export _ = return Void
|
||||||
|
|
||||||
|
getenv :: Command
|
||||||
|
getenv ((Atom varname):[]) = do
|
||||||
|
hm <- get
|
||||||
|
return $ fromMaybe Void (Map.lookup varname hm)
|
||||||
|
getenv _ = return Void
|
||||||
|
|
||||||
replace :: Command
|
replace :: Command
|
||||||
replace ((Str old) : (Str new) : (Str str) : []) =
|
replace ((Str old) : (Str new) : (Str str) : []) =
|
||||||
return $ Str $ Text.replace old new str
|
return $ Str $ Text.replace old new str
|
||||||
|
@ -60,14 +65,16 @@ toWaitingStream :: Command
|
||||||
toWaitingStream (Stream (Just h) :[]) = return (WaitingStream (Just h))
|
toWaitingStream (Stream (Just h) :[]) = return (WaitingStream (Just h))
|
||||||
toWaitingStream _ = return Void
|
toWaitingStream _ = return Void
|
||||||
|
|
||||||
internalCommands :: [(Text,Command)]
|
internalCommands :: Map.Map Text Command
|
||||||
internalCommands = [ ("prn", prn)
|
internalCommands = [ ("prn", prn)
|
||||||
, ("pr", pr)
|
, ("pr", pr)
|
||||||
, (">", toWaitingStream)
|
, (">", toWaitingStream)
|
||||||
, ("replace", replace)
|
, ("replace", replace)
|
||||||
, ("let",llet)
|
, ("let",llet)
|
||||||
, ("export",export)
|
, ("export",export)
|
||||||
]
|
, ("getenv",getenv)
|
||||||
|
, ("$",getenv)
|
||||||
|
] & Map.fromList
|
||||||
|
|
||||||
lookup :: Text -> Maybe Command
|
lookup :: Text -> Maybe Command
|
||||||
lookup = flip Prelude.lookup internalCommands
|
lookup = flip Map.lookup internalCommands
|
||||||
|
|
Loading…
Reference in a new issue