Last active
February 11, 2023 01:48
-
-
Save ae-s/539a95be59b236afabfe to your computer and use it in GitHub Desktop.
Host-dependent automatic 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
#!/bin/bash | |
# Put the contents of this file in your .bashrc, to | |
# get a prompt that is automatically a distinct, | |
# stable color on every host you log into. | |
# ^O puts terminal back into default text mode for every prompt, | |
# preventing random glyphs. | |
resetterm="\[\017\]" | |
# \[ and \] prevent the shell from counting these characters | |
# against the line length. | |
usercolor="\[\033[35m\]" # purple | |
hostcolor="\[\033[4"$(( ( $(hostname|cksum|cut -d\ -f1|cut -d\ -f1) / 7 ) % 7))"m\033[1;3"$(( $(hostname|cksum|cut -d\ -f1|cut -d\ -f1) % 7))"m\]" # bold-random-color on random-color | |
timecolor="\[\033[35m\]" # purple | |
normcolor="\[\033[0m\]" # prompt bg | |
resetcolor="\[\033[0m\]" # terminal default | |
# To put in xterm titlebar, \007 ends the string but \r backs over it | |
# for non-parsing terminals. It would be cool to change this to | |
# exclude non-parsing terminals so that my vt100 won't beep at me for | |
# every line. | |
title="\[\033]0;b:\w\007\r\]" | |
export PS1=$resetterm""$title""$normcolor"["$usercolor"\u"$normcolor"@"$hostcolor"\h"$normcolor":"$timecolor"\A"$normcolor" \j \w]\$"$resetcolor" " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment