58 lines
2.6 KiB
Bash
Executable File
58 lines
2.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# Fetches f() and fx() (plus all default sources) into a temp dir and
|
|
# sources them into your CURRENT shell -- no git, no cloning.
|
|
#
|
|
# Run with eval so sourcing happens in your real shell, not a subshell
|
|
# that vanishes when the script exits:
|
|
#
|
|
# eval "$(curl -fsSL https://huggingface.co/spaces/Daveswo/self-healing-autopoietic-shell/raw/main/contrib/fx/bootstrap.sh)"
|
|
#
|
|
# After that: f and fx are ready to use in this shell session. To keep
|
|
# them in every new shell, add the same eval line to your rc file.
|
|
|
|
_base="https://huggingface.co/spaces/Daveswo/self-healing-autopoietic-shell/raw/main"
|
|
# mktemp -d, not `mkdir -p .../self-healing-shell-$$`: a PID-based name
|
|
# under shared, world-writable /tmp is guessable, and `mkdir -p` follows
|
|
# a pre-existing symlink at that path without complaint -- an attacker
|
|
# who plants one before this runs gets the curl-fetched files written
|
|
# through it. mktemp -d always creates a fresh, unpredictable directory
|
|
# or fails outright; it never silently reuses an existing path.
|
|
_dir="$(mktemp -d "${TMPDIR:-/tmp}/self-healing-shell-XXXXXX" 2>/dev/null)"
|
|
|
|
# This runs via `eval` inline in your live interactive shell -- never
|
|
# `exit`/`return` on failure here, that would close your terminal, not
|
|
# just abort the script. Fall through to the same "skip the rest"
|
|
# if/else the original script already used.
|
|
if [ -z "$_dir" ] || [ ! -d "$_dir" ]; then
|
|
echo "bootstrap: mktemp -d failed" >&2
|
|
_fetch_ok=0
|
|
else
|
|
mkdir -p "$_dir/sources.d" 2>/dev/null
|
|
# The directory has to outlive this script -- FX_SOURCES_DIR keeps
|
|
# pointing into it for the rest of the shell session -- so it can't
|
|
# be removed right after sourcing. Clean it up when the shell
|
|
# itself exits instead, so repeated bootstrapping doesn't
|
|
# accumulate copies in /tmp.
|
|
trap 'rm -rf "$_dir"' EXIT
|
|
|
|
_fetch_ok=1
|
|
curl -fsSL "$_base/src/f.sh" -o "$_dir/f.sh" || _fetch_ok=0
|
|
curl -fsSL "$_base/contrib/fx/fx.sh" -o "$_dir/fx.sh" || _fetch_ok=0
|
|
for s in 10-known.sh 20-history.sh 30-selfdiag.sh 40-pathfuzzy.sh 50-thefuck.sh 70-local-llm.sh 80-remote-api.sh 90-team-shared.sh; do
|
|
curl -fsSL "$_base/contrib/fx/sources.d/$s" -o "$_dir/sources.d/$s" || _fetch_ok=0
|
|
done
|
|
fi
|
|
|
|
if [ "$_fetch_ok" != 1 ]; then
|
|
echo "bootstrap: fetch failed, check your connection" >&2
|
|
else
|
|
chmod +x "$_dir"/*.sh "$_dir"/sources.d/*.sh 2>/dev/null
|
|
FX_SOURCES_DIR="$_dir/sources.d"
|
|
export FX_SOURCES_DIR
|
|
. "$_dir/f.sh"
|
|
. "$_dir/fx.sh"
|
|
echo "f() and fx() are ready in this shell. Try: fx <command-that-might-fail>"
|
|
fi
|
|
|
|
unset _base _dir _fetch_ok s
|