Skip to content

Commit

Permalink
Add magic script
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Jan 16, 2025
1 parent fe7ac04 commit 33a59ed
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scripts/magic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

handler=$(cat <<EoHndlr
if [ -t 2 ] && [ \$1 != pkgx ] && pkgx pkgx^1 --silent --provider \$1; then
if pkgx gum confirm "^^ run that with \\\`pkgx\\\`?"; then
pkgx "\$@"
else
return 127
fi
else
echo "cmd not found: \$1" >&2
return 127
fi
EoHndlr
)

cat <<EoSH
if [ -n "\$ZSH_VERSION" ] && [ \$(emulate) = zsh ]; then
eval '
command_not_found_handler() {
$handler
}'
elif [ -n "\$BASH_VERSION" ] && [ "\$POSIXLY_CORRECT" != y ] ; then
eval '
command_not_found_handle() {
$handler
}'
else
echo "pkgx: warning: unsupported shell" >&2
fi
EoSH

0 comments on commit 33a59ed

Please sign in to comment.