b-ryan / powerline-shell

A beautiful and useful prompt for your shell
MIT License
6.22k stars 745 forks source link

Add segments local IP and external IP [ Feature request ] #385

Open AlvaroBernalG opened 6 years ago

AlvaroBernalG commented 6 years ago

Hello good people of powerline-shell,

Would it be possible to add local IP and external IP as segments ?

screen shot 2018-04-15 at 21 34 12

As you can see , it becomes quite useful when dealing with docker instances.

Kind Regards, Alvaro

b-ryan commented 6 years ago

I could see this being useful. Are you accomplishing this already yourself?

The local IP would need to know which interface you want to show as there may be many local IPs. But that is feasible as an argument to the segment.

AlvaroBernalG commented 6 years ago

Are you accomplishing this already yourself?

Yes. I currently have a brittle solution that I am trying to improve. I'll make a PR as soon as I finish it.

Regarding the external IP, we are going to need to use an external service that returns the external ip.

Any preferences for a particular service? I was thinking on using https://www.ipify.org/ from https://github.com/rdegges/ipify-api.

What do you think?

b-ryan commented 6 years ago

I do not have a preference. My standard way of getting my IP is

/usr/bin/dig +short myip.opendns.com @resolver1.opendns.com

But this would rely on the dig command existing, which it wouldn't on windows. So ipify would probably be a better option. This segment would be rather slow since it's making an HTTP request. I wonder if we can intelligently cache it. Maybe only every X times the prompt is shown should it actually make a request.