Tuesday, September 29, 2015

Bash alias to get the current IP in the terminal on mac

When I test iOS apps with server API I need my dev machine's local IP. I am using it to start the devserver and in the iOS app to connect to that. 
I got tired of typing ifconfig, scroll to find it and then copy and paste it so I created an alias for it.
Add this to your ~/.profile 
alias cip="ifconfig | grep 'inet ' | grep -v | awk '{print \$2}'"
After this restart the terminal or run 
source ~/.profile
Then all you have to do is type cip in the terminal to print your current IP

You can find me on twitter @LZAntal