Skip to content

Instantly share code, notes, and snippets.

@dot
Last active April 11, 2016 16:26
Show Gist options
  • Save dot/ef050dfc3e694f7f5e3adb2372cc5fbd to your computer and use it in GitHub Desktop.
Save dot/ef050dfc3e694f7f5e3adb2372cc5fbd to your computer and use it in GitHub Desktop.
IP Address for Alfred
#!/bin/bash
_LOCALS=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')
LOCALS=(`echo ${_LOCALS}`)
#LOCAL=$(ipconfig getifaddr en0)
EXTERNAL=$(curl -4 --silent http://icanhazip.com)
LITEMS=""
for ((i=0; i<${#LOCALS[*]}; i++)) do
ITEM=$(cat <<-EOS
<item uid="localip_$i" arg="${LOCALS[i]}">
<title>Local IP${i}: ${LOCALS[i]}</title>
<subtitle>Press Enter to paste, or Cmd+C to copy</subtitle>
<icon>icon.png</icon>
</item>
EOS
)
LITEMS="${LITEMS}${ITEM}"
done
cat<<EOB
<?xml version="1.0"?>
<items>
$LITEMS
<item uid="externalip" arg="$EXTERNAL">
<title>External IP: $EXTERNAL</title>
<subtitle>Press Enter to paste, or Cmd+C to copy</subtitle>
<icon>icon.png</icon>
</item>
</items>
EOB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment