Is it possible to show ip address on top bar near the time?
Is it possible to show IP address on top bar near the time? I use ubuntu 17.10 and Xorg.
Here the Image:
Solution 1:
Screenshot
Discover your current DCHP IP address
This answer should work for most Ubuntu distributions. The first step is discovering your current IP address. According to this Linux & Unix answer it isn't stored on disk in the same location across distributions. For a portable solution you need to use:
default_interface=$(route -n | awk '$1 == "0.0.0.0" {print $8; exit}')
ip_address=$(ifconfig "$default_interface" | awk 'sub(/.* inet addr:/, "") {print $1}')
echo $ip_address
192.168.1.66
Install Sysmonitor Indicator
You now need an Application Indicator that to let's you pick and choose the information to display in the Systray / Application Notification Area. I use Sysmonitor Indicator. To summarize the installation instructions in the link:
sudo add-apt-repository ppa:fossfreedom/indicator-sysmonitor
sudo apt-get update
sudo apt-get install indicator-sysmonitor
You need to configure the name of the bash script that is called and the update interval in the Advanced
tab of the Preferences
panel:
Highlight the Custom
option and click the Edit
button:
Here's a complaint I have to the developer the input field for the command is abnormally small. You can't see the whole command you are typing all at once and need arrow keys to scroll through it. Anyway assign the bash script filename. I used:
~/bin/indicator-sysmonitor-display
I already have a main bash script so I created an abbreviated version for this answer.
Create the script
Using the code from the first section create the file ~/bin/indicator-sysmonitor-display
containing:
#!/bin/bash
default_interface=$(route -n | awk '$1 == "0.0.0.0" {print $8; exit}')
systray=$(ifconfig "$default_interface" | awk 'sub(/.* inet addr:/, "") {print $1}')
echo "$systray" # sysmon-indidicator will put echo string into systray for us.
exit 0