2023-11-25

  • Upgraded this to be two shell functions that I have in my bash profile that don’t require Raycast Text snippets (which were borking in the VSCode Terminal)
# Echo all processes using a given port
function up() {
    local port=$1
    local pids=$(lsof -t -i :$port)
 
    if [[ -n $pids ]]; then
        echo "Processes using port $port:"
        echo "$pids"
    else
        echo "No processes found using port $port."
    fi
}
 
# Kill All Processes Using Port
function kp() {
    local port=$1
    local pids=$(lsof -t -i :$port)
 
    if [[ -n $pids ]]; then
        echo "Processes using port $port:"
        echo "$pids"
        echo "Killing processes..."
        kill $pids
        echo "Processes killed."
    else
        echo "No processes found using port $port."
    fi
}
  • 2023-10-13
    • Learned about the -t flag on lsof. It will just return the port #‘s
    • I’ve been using lsof for years, but as a two-step process. Now I can do it all in one go.
    • I went ahead and added a snippet for this in Raycast sudo kill -kill $(sudo lsof -t -i :5432)