Skip to content

Instantly share code, notes, and snippets.

@rszamszur
Forked from r2r-dev/bash-anywhere.sh
Created March 17, 2022 20:44
Show Gist options
  • Save rszamszur/81ebc2e9cd55b49c613906a2243d01ac to your computer and use it in GitHub Desktop.
Save rszamszur/81ebc2e9cd55b49c613906a2243d01ac 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