Skip to content

Commit

Permalink
fix bk edit outside a pantry clone
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Dec 13, 2023
1 parent 11ec865 commit 3ed2f9e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions bin/cmd/edit
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
#!/usr/bin/env -S pkgx +deno bash
#!/usr/bin/env -S pkgx +deno +git bash

set -eo pipefail

d="$(cd "$(dirname "$0")" && pwd)"

if test -z "$1"; then
if test -z "$PKGX_PANTRY_PATH"; then
echo "error: PKGX_PANTRY_PATH is not set" >&2
exit 1
fi
d="$(cd "$(dirname "$0")" && pwd)"

for x in $(echo "$PKGX_PANTRY_PATH" | tr ':' '\n'); do
if test -z "$PKGS" -a -d "$x"/.git; then
#^^^^^^^^^^^^^^^ stop at first match
PKGS=($(GIT_WORK_TREE="$x" "$d/status" --print-paths))
PKGS=($(GIT_WORK_TREE="$x" bash "$d/status" --print-paths))
fi
done
else
PKGS=($(deno run --allow-read --allow-env - <<EoTS
IFS=$'\n'
PKGS=($(cd $d/../.. && deno run --allow-read --allow-env - "$@" <<EoTS
import { hooks } from "pkgx";
const pp = Deno.args.map(arg => hooks.usePantry().find(arg).then(x => x.map(y => y.path.string)));
const paths = await Promise.all(pp);
console.log(paths.flatMap(x => x).join("\n"));
paths.flat().forEach(x => console.log(x));
Deno.exit(0);
EoTS
))

echo "${PKGS[@]}"
fi

if test -z "$EDITOR"; then
Expand Down Expand Up @@ -53,7 +54,7 @@ if test -z "$PKGS"; then
echo "usage: bk edit <pkgspec>" >&2
fi
exit 1
elif test "$EDITOR" = code; then
elif test "$EDITOR" = code -a -n "$PKGX_PANTRY_PATH"; then
exec $EDITOR "$PKGX_PANTRY_PATH" "${PKGS[@]}"
# ^^ be more useful
else
Expand Down

0 comments on commit 3ed2f9e

Please sign in to comment.