Skip to content

Commit f0cc108

Browse files
committed
ENH: Support symlinks like .local/bin/npm -> sandbox-run
1 parent c1fc055 commit f0cc108

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

sandbox-run

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ command -v bwrap >/dev/null || { command bwrap; echo 'Error: Missing /usr/bin/bw
66

77
# Support symlinks e.g. ./local/bin/npm -> /usr/bin/sandbox-run
88
bin="$0"
9-
if [ "${bin##*/}" = 'sandbox-run' ]; then
9+
if [ "${bin##*/}" != 'sandbox-run' ]; then
10+
IFS=:
11+
for d in ${PATH:-/usr/local/bin:/usr/bin:/bin}; do
12+
p="$d/${0##*/}"
13+
[ "$0" != "$p" ] && [ -x "$p" ] && bin="$p" && break || true
14+
done
15+
unset IFS
16+
else
1017
if [ "$#" -eq 0 ]
1118
then echo "Usage: ${0##*/} ARG..."; exit 1
12-
else bin="${1:-}"; shift
19+
else bin="$1"; shift
1320
fi
1421
fi
1522

tests/test-symlinks.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
. "${0%/*}/_init.sh"
5+
6+
ln -s "$(command -v sandbox-run)" npm
7+
PATH="$(pwd):$PATH"
8+
9+
npm --version |& grep -q 'sandbox-run'
10+
npm --help |& grep -q 'install'

0 commit comments

Comments
 (0)