a couple of prompts of claude code gave me this, works well enough, but while I agree that this is sometimes useful, it may indeed better served by a couple of aliases in the terminal ``` #!/bin/bash
# SwiftBar Port Monitor # Monitors processes on TCP ports 2000-6000
# Menu bar title echo " Ports" echo "---"
# Get processes listening on TCP ports 2000-6000 processes=$(lsof -iTCP:2000-6000 -sTCP:LISTEN -n -P 2>/dev/null | awk 'NR>1 {print $2 "|" $1 "|" $9}' | sort -t'|' -k3 -n)
if [ -z "$processes" ]; then echo "No processes found on ports 2000-6000" exit 0 fi
# Process each line while IFS='|' read -r pid name port_info; do if [ -n "$pid" ] && [ -n "$name" ] && [ -n "$port_info" ]; then # Extract port number from format like :3000 port=$(echo "$port_info" | sed 's/.://')
# Menu item with port and process name
echo "[$port] $name | color=blue"
# Submenu items
echo "--Kill (TERM) | shell=kill param1=$pid terminal=false refresh=true"
echo "--Kill Force (KILL) | shell=kill param1=-9 param2=$pid terminal=false refresh=true"
echo "--Process Info | shell=ps param1=-p param2=$pid param3=-o param4=pid,ppid,user,command terminal=true"
echo "-----"
fi
done <<< "$processes"# Refresh option echo "---" echo "Refresh | refresh=true