Skip to content

Commit

Permalink
Fix init/edit
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Dec 16, 2023
1 parent 717f610 commit 95dc2a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
24 changes: 13 additions & 11 deletions bin/cmd/edit
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
#!/usr/bin/env -S pkgx +deno +git bash

set -eo pipefail
set -exo pipefail

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

if test -z "$1"; then
if test -z "$PKGX_PANTRY_PATH"; then
if [ -z "$1" ]; then
if [ -z "$PKGX_PANTRY_PATH" ]; then
echo "error: PKGX_PANTRY_PATH is not set" >&2
exit 1
fi

for x in $(echo "$PKGX_PANTRY_PATH" | tr ':' '\n'); do
if test -z "$PKGS" -a -d "$x"/.git; then
if [ -z "$PKGS" -a -d "$x"/.git ]; then
#^^^^^^^^^^^^^^^ stop at first match
PKGS=($(GIT_WORK_TREE="$x" bash "$d/status" --print-paths))
PKGS=($(GIT_WORK_TREE="$x" bash "$d/bin/cmd/status" --print-paths))
fi
done
elif [ -f "$d"/projects/$1/package.yml ]; then
PKGS=($1)
else
IFS=$'\n'
PKGS=($(cd $d/../.. && deno run --allow-read --allow-env - "$@" <<EoTS
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);
Expand All @@ -28,7 +30,7 @@ EoTS
))
fi

if test -z "$EDITOR"; then
if [ -z "$EDITOR" ]; then
if command -v code >/dev/null; then
EDITOR="code"
elif command -v vim >/dev/null; then
Expand All @@ -41,20 +43,20 @@ if test -z "$EDITOR"; then
echo "error: \`\$EDITOR\` is not set" >&2
exit 1
fi
elif test "$EDITOR" = code_wait; then
elif [ "$EDITOR" = code_wait ]; then
# this is for mxcl who generally prefers his editor to wait
# but not in this case. #perks-of-making-the-thing
EDITOR=code
fi

if test -z "$PKGS"; then
if [ -z "$PKGS" ]; then
if [ -n "$PKGX_PANTRY_PATH" ]; then
echo "error: no new packages in \`\$PKGX_PANTRY_PATH\`" >&2
else
echo "usage: bk edit <pkgspec>" >&2
fi
exit 1
elif test "$EDITOR" = code -a -n "$PKGX_PANTRY_PATH"; then
elif [ "$EDITOR" = code -a -n "$PKGX_PANTRY_PATH" ]; then
exec $EDITOR "$PKGX_PANTRY_PATH" "${PKGS[@]}"
# ^^ be more useful
else
Expand Down
14 changes: 7 additions & 7 deletions bin/cmd/init
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env -S pkgx +shuf bash>=4
#!/usr/bin/env -S pkgx +shuf +gum bash>=4
# shellcheck shell=bash

set -eo pipefail
set -exo pipefail

if test -z "$PKGX_PANTRY_PATH"; then
echo "error: PKGX_PANTRY_PATH is not set" >&2
Expand All @@ -21,10 +21,10 @@ if ! git status --porcelain; then
exit 1
fi

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

if [ -f /usr/share/dict/words ]; then
BLEND=$(paste <(shuf -n 1 /usr/share/dict/words) <(shuf -n 1 /usr/share/dict/words) -d '-')
BLEND=wip.$(shuf -n 1 /usr/share/dict/words).org
else
BLEND=example.com
fi
Expand All @@ -43,15 +43,15 @@ if test "$(git rev-parse --abbrev-ref HEAD)" != "new/$BLEND"; then
git branch --unset-upstream # ask jacob why
fi

pkgx gum format <<EOF
gum format <<EOF
# created \`$PRETTY\`

Now type \`edit\` to open the yaml in your \`\$EDITOR\`
Now type \`bk edit\` to open the yaml in your \`\$EDITOR\`

the package will need renaming before we can merge it.
we typically name packages after their homepage.

if you aren’t sure about the name you can submit and we’ll assist.
EOF

exec "$d/edit" $BLEND
exec bash "$d/bin/cmd/edit" $BLEND

0 comments on commit 95dc2a3

Please sign in to comment.