I want to have a standard BASH PS1 prompt that will automatically have a colour set based upon the hostname of the server.
This would meant that whenever logging into a server, it would instantly be clear and familiar that you are on that server as the prompt colour would be different to other servers
A given hostname must always give the same colour
I have found similar ideas with hex codes, but this is specifically for use with BASH colours
The idea would then be that there can be a standard bash prompt code snippet that can be included everywhere and will always give different colours for different servers without any further code changes
In a nutshell, the question is what bash function could you write that will take 2 arguments - a string and a hash. It should echo out the string in a colour that is determined by the hash, and the colour should always be the same for any given hash
EDIT - TO CLARIFY
the answers so far assume that host names are known in advance
I am looking for something that will assign the same random colour deterministically based on whatever host name is for that server
I am definitely not looking for something that requires any kind of code change when installing the PS1 on a new server
This post is along the lines but doesn't seem to have a simple PS1 snippet that I can use https://aweirdimagination.net/2015/02/28/better-hash-based-colors/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…