+# ------------------------------------------------------------------ kill ----
+# Terminate every Borderlands 2 process we launched (game exe + umu/Proton/Wine
+# tree for our prefixes), SIGTERM first then SIGKILL. Scoped to our BASE dir so it
+# won't touch unrelated Wine apps.
+kill_instances() {
+ local sig
+ for sig in TERM KILL; do
+ pkill -"$sig" -f 'Borderlands2\.exe' 2>/dev/null # proton game
+ pkill -"$sig" -x 'Borderlands2' 2>/dev/null # native game
+ pkill -"$sig" -f "$BASE/p[12]/" 2>/dev/null # umu/proton/wine for our copies+prefixes
+ [ "$sig" = TERM ] && sleep 2
+ done
+}
+
+cmd_kill() {
+ # Match the process NAME (comm) as a substring, not the full cmdline - otherwise
+ # helper shells that merely have the game path in their args get counted. This
+ # matches "Borderlands2.ex" (Proton, 15-char truncated) and "Borderlands2".
+ pgrep 'Borderlands2' >/dev/null || { ok "No Borderlands 2 instances running."; return 0; }
+ say "Killing Borderlands 2 instances..."
+ kill_instances
+ # pgrep -c prints "0" and exits non-zero on no match, so DON'T add `|| echo 0`
+ # (that would double it). Command substitution keeps the "0" regardless of exit.
+ local left; left=$(pgrep -c 'Borderlands2' 2>/dev/null); left=${left:-0}
+ [ "$left" = 0 ] && ok "All instances killed." || warn "$left process(es) still lingering."
+}
+