Skip to content

Instantly share code, notes, and snippets.

@gpalo
gpalo / .bashrc
Last active June 16, 2021 19:21
Copy the IP of an interface to the clipboard (.bashrc and .zshrc version available)
#make sure you have xclip installed (E.g: sudo apt install xclip)
#Add the below lines to your ~/.bashrc (or something similar), don't forget to: source ~/.bashrc
#Inside your terminal you can now press ctrl+p to copy the ip of interface 'tun0' to your clipboard
#function to get the IP of the specified interface name and copy it to the x11 clipboard
copy_interface_ip() {
ip addr show $@ | grep inet -m1 | awk '{print $2}' | echo -n $(cut -d/ -f1) | xclip -selection c
}
#new bind (ctrl+p) to execute the copy_interface_ip function