Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not enable export when sourcing rc file #553

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ pre-commit:
run: npm run eslint {staged_files}
```

Provide a tweak to access `npm` executable the same way you do it in your ~/<shell>rc
Provide a tweak to access `npm` executable the same way you do it in your ~/<shell>rc.

```yml
# lefthook-local.yml
Expand All @@ -254,16 +254,25 @@ Provide a tweak to access `npm` executable the same way you do it in your ~/<she
rc: ~/.lefthookrc
```

Or

```yml
# lefthook-local.yml

# If the path contains spaces, you need to quote it.
rc: '"${XDG_CONFIG_HOME:-$HOME/.config}/lefthookrc"'
```

In the rc file, export any new environment variables or modify existing ones.

```bash
# ~/.lefthookrc

# An nvm way

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

# Or maybe just

PATH=$PATH:$HOME/.nvm/versions/node/v15.14.0/bin
mrexox marked this conversation as resolved.
Show resolved Hide resolved
```

Expand Down
3 changes: 1 addition & 2 deletions internal/templates/hook.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ if [ "$LEFTHOOK" = "0" ]; then
fi

{{- if .Rc}}
{{/* Load rc file and export all ENV vars defined in it */}}
set -a
{{/* Load rc file, which may export ENV variables */}}
[ -f {{.Rc}} ] && . {{.Rc}}
{{- end}}

Expand Down