#!/bin/sh
# Socket Firewall shim: runs the package manager it is named after through
# sfw. Installed by omarchy-install-development-socket as npm, npx, yarn,
# pnpm, pip, pip3 and uv in ~/.local/share/omarchy/sfw-shims, which goes
# first on PATH. The shim takes its own directory off PATH, finds the real
# command, and runs it through sfw; straight when sfw is missing or
# OMARCHY_SFW_DISABLE is set, so an install never breaks on the firewall.
set -eu
cmd=$(basename "$0")
shim_dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
PATH=$(printf '%s' "$PATH" | awk -v RS=: -v d="$shim_dir" \
  '$0 != d && $0 != "" { printf "%s%s", s, $0; s = ":" }')
export PATH
real=$(command -v "$cmd" 2>/dev/null || true)
if [ -z "$real" ]; then
  echo "sfw shim: $cmd not found on PATH" >&2
  exit 127
fi
if [ -n "${OMARCHY_SFW_DISABLE:-}" ]; then
  exec "$real" "$@"
fi
sfw_bin=$(command -v sfw 2>/dev/null || true)
if [ -z "$sfw_bin" ]; then
  exec "$real" "$@"
fi
exec "$sfw_bin" "$real" "$@"
