Skip to content

Commit

Permalink
Only define x if available; Refs #857 (#858)
Browse files Browse the repository at this point in the history
* Only define `x` if available; Refs #857
* Note that this doesn’t change the behavior of the command not found handler, that should be a separate more involved fix.
* Add test
  • Loading branch information
mxcl authored Nov 17, 2023
1 parent 87bb929 commit e441d0c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.shellcode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,24 @@ jobs:
echo 'dev did not fail when already activated' >&2
exit 1
fi
x-already-defined-works:
needs: compile
runs-on: ubuntu-latest
defaults:
run:
shell: zsh -eo pipefail {0}
steps:
- uses: actions/download-artifact@v3
with:
path: /usr/local/bin
name: pkgx
- name: prep
run: |
sudo apt-get update && sudo apt-get --yes install zsh libatomic1
chmod u+x /usr/local/bin/pkgx
shell: sh
- run: |
alias x="echo hi"
eval "$(pkgx --shellcode)"
test "$(x)" = hi
42 changes: 22 additions & 20 deletions src/modes/shellcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,26 @@ export default function() {
esac
}
x() {
case $1 in
"")
if [ -f "${tmp}/shellcode/x.$$" ]; then
if foo="$("${tmp}/shellcode/u.$$")"; then
eval "$foo"
${sh} "${tmp}/shellcode/x.$$"
unset foo
fi
rm "${tmp}/shellcode/"?.$$
else
echo "pkgx: nothing to run" >&2
return 1
fi;;
*)
command pkgx -- "$@";;
esac
}
if ! type x >/dev/null 2>&1; then
eval 'x() {
case $1 in
"")
if [ -f "${tmp}/shellcode/x.$$" ]; then
if foo="$("${tmp}/shellcode/u.$$")"; then
eval "$foo"
${sh} "${tmp}/shellcode/x.$$"
unset foo
fi
rm "${tmp}/shellcode/"?.$$
else
echo "pkgx: nothing to run" >&2
return 1
fi;;
*)
command pkgx -- "$@";;
esac
}'
fi
env() {
for arg in "$@"; do
Expand All @@ -78,8 +80,8 @@ export default function() {
done
if [ $# -eq 0 ]; then
command env
fi
if type _pkgx_reset >/dev/null 2>&1; then
return
elif type _pkgx_reset >/dev/null 2>&1; then
_pkgx_reset
fi
eval "$(command pkgx --internal.use "$@")"
Expand Down

0 comments on commit e441d0c

Please sign in to comment.