Change the prompt for production systems

1 minute read Published:

At my job all new systems have the string “-prd-” in the hostname. …

http://stackoverflow.com/questions/229551/string-contains-in-bash Compatible answer

The [i]path[/i] function is a fix for a problem in some sh shells. [code]path() { if test -x /usr/bin/$1 ; then ${1+"/usr/bin/$@"} elif test -x /bin/$1 ; then ${1+"/bin/$@"} fi }

Colored production prompt

if test -z “${HOSTNAME##-prd-}” -a -t; then _bred="$(path tput bold 2> /dev/null; path tput setaf 1 2> /dev/null)" _sgr0="$(path tput sgr0 2> /dev/null)" # Only set the color if it is not set yet if test -n “${PS1##$_bred}”; then PS1="[$_bred]$PS1[$_sgr0]" fi unset _bred _sgr0 fi [/code]

Recent posts
- full list -