Skip to content

Instantly share code, notes, and snippets.

@teebow1e
Created September 27, 2024 17:48
Show Gist options
  • Save teebow1e/135a0e34ad96f92f2ba932bd1dec5356 to your computer and use it in GitHub Desktop.
Save teebow1e/135a0e34ad96f92f2ba932bd1dec5356 to your computer and use it in GitHub Desktop.
add ip address of an interface to bash PS1
get_ip() {
    # Replace 'eth0' with your interface name, such as 'wlan0' for Wi-Fi
    local interface="ens33"
    ip addr show $interface 2>/dev/null | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1
}

then add [$(get_ip)] to PS1 var

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment