mirror of
https://github.com/kastdeur/dotfiles.git
synced 2025-01-02 14:03:31 +01:00
[bash] rewrite hostname colouring
This commit is contained in:
parent
12f86b412b
commit
b8f391ae20
1 changed files with 35 additions and 14 deletions
|
@ -52,21 +52,42 @@ function vte_thing() {
|
||||||
|
|
||||||
export PROMPT_COMMAND=__prompt_command
|
export PROMPT_COMMAND=__prompt_command
|
||||||
|
|
||||||
function __colored_hostname() {
|
function __PS1_hostname() {
|
||||||
local HOST="${1:-$HOSTNAME}"
|
# returns a formatted hostname
|
||||||
local color="${2:-$(color)}"
|
local color="${2:-$(color)}"
|
||||||
local PS1
|
|
||||||
|
|
||||||
if color ; then
|
# no colours? no need to run
|
||||||
case "${HOST%%.*}" in
|
if ! color ; then
|
||||||
'locksmith') PS1+="${Pur}\h${RCol}";;
|
echo "\h";
|
||||||
'bladesmith') PS1+="${Yel}\h${RCol}";;
|
return
|
||||||
'gunsmith') PS1+="${Red}\h${RCol}";;
|
fi
|
||||||
'goldsmith') PS1+="${IYel}\h${RCol}";;
|
|
||||||
*) PS1+="${Blu}${On_Whi}\h${RCol}";;
|
local HOST="${1:-$HOSTNAME}"
|
||||||
esac
|
local PS1
|
||||||
else
|
local NOMATCH
|
||||||
PS1+="\h"
|
local func_extension="__PS1_hostname_extended"
|
||||||
|
|
||||||
|
# check selected hostnames
|
||||||
|
case "${HOST%%.*}" in
|
||||||
|
'locksmith') PS1+="${Pur}\h${RCol}";;
|
||||||
|
'bladesmith') PS1+="${Yel}\h${RCol}";;
|
||||||
|
'gunsmith') PS1+="${Red}\h${RCol}";;
|
||||||
|
'goldsmith') PS1+="${IYel}\h${RCol}";;
|
||||||
|
*) NOMATCH=1;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -n "${NOMATCH}" ]; then
|
||||||
|
if [ x$(type -t "$func_extension") = xfunction ]; then
|
||||||
|
NOMATCH=$($func_extension "$@")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# extended colouring
|
||||||
|
if [ -z "${NOMATCH}" ]; then
|
||||||
|
PS1+="${NOMATCH}"
|
||||||
|
# default colouring
|
||||||
|
else
|
||||||
|
PS1+="${Blu}${On_Whi}\h${RCol}";
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$PS1"
|
echo "$PS1"
|
||||||
|
@ -124,7 +145,7 @@ function __prompt_command() {
|
||||||
PS1+="@"
|
PS1+="@"
|
||||||
|
|
||||||
if color ; then
|
if color ; then
|
||||||
PS1+="$(__colored_hostname)"
|
PS1+="$(__PS1_hostname)"
|
||||||
else
|
else
|
||||||
PS1+="\h"
|
PS1+="\h"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue