Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

Monday, October 8, 2012

How to get the host IP address to appear in a bash command prompt on OSX

This was done on OSX Mountain Lion.

Simply modify .bashrc to use the PS1= construct:

PS1="[\u@\[\e[0;33m\]MBP @ `ifconfig|grep broadcast|awk ' { print $2 }'` \[\e[0m\]\W]$ "

The key bit is enclosed in `...`.  Note that modifying this for other *nix systems requires fiddling with the search string.  Also note that the complex [\e[0;33m\]... construct controls the prompt color.  There are some great online tutorials about that.  Just Google "bash color prompt".

Result:
PS1 line in .bashrc to get IP address in command prompt on OSX.