Skip to content

Commit 3ed2f9e

Browse files
committed
fix bk edit outside a pantry clone
1 parent 11ec865 commit 3ed2f9e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

bin/cmd/edit

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
#!/usr/bin/env -S pkgx +deno bash
1+
#!/usr/bin/env -S pkgx +deno +git bash
22

33
set -eo pipefail
44

5+
d="$(cd "$(dirname "$0")" && pwd)"
6+
57
if test -z "$1"; then
68
if test -z "$PKGX_PANTRY_PATH"; then
79
echo "error: PKGX_PANTRY_PATH is not set" >&2
810
exit 1
911
fi
10-
d="$(cd "$(dirname "$0")" && pwd)"
12+
1113
for x in $(echo "$PKGX_PANTRY_PATH" | tr ':' '\n'); do
1214
if test -z "$PKGS" -a -d "$x"/.git; then
1315
#^^^^^^^^^^^^^^^ stop at first match
14-
PKGS=($(GIT_WORK_TREE="$x" "$d/status" --print-paths))
16+
PKGS=($(GIT_WORK_TREE="$x" bash "$d/status" --print-paths))
1517
fi
1618
done
1719
else
18-
PKGS=($(deno run --allow-read --allow-env - <<EoTS
20+
IFS=$'\n'
21+
PKGS=($(cd $d/../.. && deno run --allow-read --allow-env - "$@" <<EoTS
1922
import { hooks } from "pkgx";
2023
const pp = Deno.args.map(arg => hooks.usePantry().find(arg).then(x => x.map(y => y.path.string)));
2124
const paths = await Promise.all(pp);
22-
console.log(paths.flatMap(x => x).join("\n"));
25+
paths.flat().forEach(x => console.log(x));
2326
Deno.exit(0);
2427
EoTS
2528
))
26-
27-
echo "${PKGS[@]}"
2829
fi
2930

3031
if test -z "$EDITOR"; then
@@ -53,7 +54,7 @@ if test -z "$PKGS"; then
5354
echo "usage: bk edit <pkgspec>" >&2
5455
fi
5556
exit 1
56-
elif test "$EDITOR" = code; then
57+
elif test "$EDITOR" = code -a -n "$PKGX_PANTRY_PATH"; then
5758
exec $EDITOR "$PKGX_PANTRY_PATH" "${PKGS[@]}"
5859
# ^^ be more useful
5960
else

0 commit comments

Comments
 (0)