Created
March 24, 2023 04:36
-
-
Save morgajel/db9c4a32a63957ec17f6e79157e860d9 to your computer and use it in GitHub Desktop.
.bashrc prompt colorization
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
if [[ "$TERM" == "xterm-256color" ]] ; then | |
# This snippet can replace the existing block in your .bashrc and provides the following benefits: | |
# 1. It checksums your host's FQDN, then assigns a color so your prompt for it. This means every host has a (semi) unique color | |
# 2. it checksums your username, then does the same thing. | |
# This means your username is always the same color, and your hostname is consistent-yet-different. | |
# colors range between 21 and 231 on this page: https://robotmoon.com/256-colors/#shell-prompt | |
# enjoy! - morgajel | |
num=$((0x$(echo `hostname -f` | md5sum | cut -f 1 -d " " | cut -c 1-4))) | |
color=$((num%210+21)) | |
num=$((0x$(echo $LOGNAME | md5sum | cut -f 1 -d " " | cut -c 1-4))) | |
ucolor=$((num%210+21)) | |
usercolor='\[$(tput setaf $ucolor)\]\u\[$(tput sgr0)\]' | |
atcolor='\[$(tput setaf 245)\]@\[$(tput sgr0)\]' | |
hostcolor='\[$(tput setaf $color)\]\h\[$(tput sgr0)\]' | |
coloncolor='\[$(tput setaf 245)\]:\[$(tput sgr0)\]' | |
pathcolor='\[$(tput setaf 12)\]\w\[$(tput sgr0)\]' | |
endcolor='\[$(tput setaf 245)\]\$\[$(tput sgr0)\] ' | |
PS1='${debian_chroot:+($debian_chroot)}'$usercolor$atcolor$hostcolor$coloncolor$pathcolor$endcolor | |
elif [ "$color_prompt" = yes ]; then | |
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' | |
else | |
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment