Gabriella439 / turtle

Shell programming, Haskell style
BSD 3-Clause "New" or "Revised" License
943 stars 90 forks source link

Check if an environment variable is set #452

Open 9999years opened 8 months ago

9999years commented 8 months ago

In Bash, it's very common to check if an environment is set and non-empty with [[ -n "${VAR:-}" ]]. We should provide helpers for this, like so:

hasEnv :: Text -> IO Bool
hasEnv = not . missingEnv

missingEnv :: Text -> IO Bool
missingEnv name = null $ fromMaybe "" $ need name
Gabriella439 commented 8 months ago

Let me know if https://github.com/Gabriella439/turtle/pull/454 looks okay to you