-
-
Save itsthatguy/d097b4cb304407a4858c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
pattern=$1 | |
PORTS="" | |
if [ -z "$pattern" ]; then | |
PORTS=$(lsof -iTCP -sTCP:LISTEN) | |
else | |
PORTS=$(lsof -iTCP -sTCP:LISTEN | grep -i "$pattern") | |
fi | |
i=0 | |
echo "<?xml version='1.0'?><items>" | |
while read -r line; do | |
if [ $i -gt 0 ]; then | |
x=($line) | |
boop=$(cut -d ":" -f 2 <<< "${x[8]}") | |
echo "<item uid='${x[1]}' arg='' valid='yes'> | |
<title>${x[0]}: ${boop}</title> | |
<subtitle>PID: ${x[1]}</subtitle> | |
<icon>icon_port.png</icon> | |
</item>" | |
fi | |
((i++)) | |
done <<<"$PORTS" | |
echo '</items>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment