Gabriella439 / turtle

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

Check if an environment variable is set #452

Open 9999years opened 6 months ago

9999years commented 6 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 6 months ago

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