ohmyzsh/plugins/dotenv/dotenv.plugin.zsh
Mahmoud Zalt 91b09eb848 Add a message informing users about parsing errors
I couldn't tell why I got this error `.env: line 129: syntax error near unexpected token `('` after adding a bunch of plugins.
I didn't knew what most of the plugins do, nor what the `dotenv` plugin is doing behind the scene!
After figuring out the problem, I though it would be much better displaying an error message only in case there are some parsing errors. Now I would get this:

```
Found some errors while parsing your .env file:
.env: line 129: syntax error near unexpected token `('
```
2017-10-06 07:25:01 +03:00

14 lines
256 B
Bash

#!/bin/zsh
source_env() {
if [[ -f .env ]]; then
if errs=$(bash -n .env 2>&1);
then source .env;
else
printf '%s\n' "Found some errors while parsing your .env file: " "$errs";
fi
fi
}
autoload -U add-zsh-hook
add-zsh-hook chpwd source_env