Skip to content

Commit

Permalink
Get the path from dirname instead of using Bash variable operators
Browse files Browse the repository at this point in the history
On Windows, under certain circumstances, the path separator is "\".

This change will ensure compatibility with both Linux and Windows path separators
  • Loading branch information
Carlos Cerrillo committed Jun 12, 2024
1 parent da40de3 commit c65ec43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions husky
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env sh
[ "$HUSKY" = "2" ] && set -x
if command -v cygpath >/dev/null 2>&1; then
u0=$(cygpath -u "$0")
if [ "$0" != "$u0" ]; then
exec "$u0" "$@"
fi
fi

h="${0##*/}"
s="${0%/*/*}/$h"

Expand Down
2 changes: 1 addition & 1 deletion index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default (d = '.husky') => {
f.mkdirSync(_(), { recursive: true })
w(_('.gitignore'), '*')
f.copyFileSync(new URL('husky', import.meta.url), _('h'))
l.forEach(h => w(_(h), `#!/usr/bin/env sh\n. "\${0%/*}/h"`, { mode: 0o755 }))
l.forEach(h => w(_(h), `#!/usr/bin/env sh\n. "\$(dirname "\$0")/h"`, { mode: 0o755 }))
w(_('husky.sh'), '')
return ''
}

0 comments on commit c65ec43

Please sign in to comment.