Skip to content

Commit

Permalink
fix: Do not enable export when sourcing rc file
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Sep 22, 2023
1 parent b67182f commit b91e753
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
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
```

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

0 comments on commit b91e753

Please sign in to comment.