website-htmx-rustelo-code/scripts/build/kill-3030.nu
2026-07-10 03:44:13 +01:00

41 lines
No EOL
1.4 KiB
Text
Executable file
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env nu
# Kill Process on Ports Script
# Nushell version of kill-3030.sh
# Kills processes running on ports 3030 and 3031
def main [] {
print $"(ansi blue)🔪 Killing processes on development ports...(ansi reset)"
kill_port_processes 3030
kill_port_processes 3031
print $"(ansi green)✅ Port cleanup completed(ansi reset)"
}
# Kill processes on a specific port
def kill_port_processes [port: int] {
print $"(ansi yellow)🔍 Checking port ($port)...(ansi reset)"
try {
# Get PIDs of processes using the port
let pids = (lsof -ti $":($port)" | lines | where {|line| not ($line | str trim | is-empty)})
if ($pids | is-empty) {
print $"(ansi blue) No processes found on port ($port)(ansi reset)"
} else {
print $"(ansi yellow)⚠️ Found ($pids | length) process(es) on port ($port): ($pids | str join ', ')(ansi reset)"
for pid in $pids {
try {
kill -9 ($pid | into int)
print $"(ansi green)✅ Killed process ($pid) on port ($port)(ansi reset)"
} catch {
print $"(ansi red)❌ Failed to kill process ($pid) on port ($port)(ansi reset)"
}
}
}
} catch {
print $"(ansi blue) No processes found on port ($port) (lsof failed)(ansi reset)"
}
}