0

I very often use a simple curl command to get IP addresses details. curl ipinfo.io/111.222.333.444

Almost everytime I got the IP address in the clipboard

Is there a way to use a bash variable to automatically have the clipboard value use for IP address?

Ideally I'd like to create an alias Alias iploc = 'curl ipinfo.io/{pbcopy}'

So then each time I copy an ip address in clipboard I can just type "iploc" in terminal and get the result. l

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
Laurent
  • 37
  • 1
  • 4

1 Answers1

3

You can use xsel to access the clipboard

iploc='curl ipinfo.io/$(xsel -o)'

see also Pipe to/from the clipboard in Bash script and How do I send stdin to the clipboard?

Xiaofeng
  • 151
  • 5
  • Thanks Morris. I realised that I did not mention I was on MacOS. I believe xsel is Linux only. I did some research and pbpaste seems to be the equivalent for MacOS. Created that alias: alias iploc='curl ipinfo.io/$(pbpaste)' Works like a charm. Thanks again for pointing me in the right direction. – Laurent Nov 28 '18 at 03:36