-
-
Save pocco81/98533b157790eaa6219864db1694d6db to your computer and use it in GitHub Desktop.
Show IP address in bash prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set the prompt to include the IP address instead of hostname | |
function get_ip () { | |
IFACE=$(ip -4 route | grep default | head -n1 | awk '{print $5}') | |
if [ ! -z $IFACE ]; then | |
echo -n "|"; ip -4 -o addr show scope global $IFACE | awk '{gsub(/\/.*/, "|",$4); print $4}' | paste -s -d "" | |
else | |
echo -n "||" | |
fi | |
} | |
if [ "$color_prompt" = yes ]; then | |
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[01;34m\]@\[\033[32m\]$(get_ip)\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' | |
else | |
PS1='${debian_chroot:+($debian_chroot)}\u@$(get_ip):\w\$ ' | |
fi | |
unset color_prompt force_color_prompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment