Skip to content

Instantly share code, notes, and snippets.

@r2r-dev
Last active March 18, 2022 07:19
Show Gist options
  • Save r2r-dev/947e2e6f37d4eca1fab0a4e9828c497d to your computer and use it in GitHub Desktop.
Save r2r-dev/947e2e6f37d4eca1fab0a4e9828c497d to your computer and use it in GitHub Desktop.
Bring your own shell together with your script. Stop giving a damn about {zsh, ksh, csh, ash, dash, fish} compatibility and focus on the actual work.
#!/bin/sh -
if [ "$1" != "--wrapped" ]; then
echo "[uw] start"
WD="$(mktemp -d)"
echo "[uw] download deps"
curl -L -s https://github.com/robxu9/bash-static/releases/download/5.1.016-1.2.2/bash-linux-x86_64 \
-o "${WD}/bsh" && chmod +x "${WD}/bsh"
curl -L -s http://landley.net/toybox/downloads/binaries/0.8.6/toybox-x86_64 \
-o "${WD}/toybox" && chmod +x "${WD}/toybox"
for i in $(
"${WD}/toybox"\
| "${WD}/toybox" sed 's| |\n|g'
); do
"${WD}/toybox" ln -s "${WD}/toybox" "${WD}/${i}";
done
echo "[uw] switching shells"
PATH="${WD}" bsh -- "$0" --wrapped "$@"
echo "[uw] cleanup"
rm -rf "${WD}"
echo "[uw] exit"
exit
fi
echo "[w] start"
shift
echo "[w] work"
env | grep ^PATH
which sed
printf '%q ' "$@"
echo
echo "[w] exit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment