I would like to show hostname at the beginning of the prompt in Powerline-Plain [Bash-it] theme.
Something like: MYHOSTNAME root /var/www
and I'd like to assign to it a different random and fixed color for each different hostname.
I would like to show hostname at the beginning of the prompt in Powerline-Plain [Bash-it] theme.
Something like: MYHOSTNAME root /var/www
and I'd like to assign to it a different random and fixed color for each different hostname.
\h is what you need to display the hostname in your bash prompt. In order for it to appear in a certain color, you need to wrap that part in the color codes you like. Like this you can define the color RED when you are root for example.
USERCOLOR='\[\e[1m\]'
NORMCOLOR='\[\e[m\]'
# If I am root, set the prompt to bright red
if [ ${UID} -eq 0 ]; then USERCOLOR='\[\e[1;31;7;47m\]'; fi
PS1="[$USERCOLOR\h$NORMCOLOR]\\n\#-\\$> "
Just overwrite the POWERLINE_PROMPT variable in your .bashrc file and add hostname like this:
export POWERLINE_PROMPT=${POWERLINE_PROMPT:="hostname user_info scm python_venv ruby node cwd"}
As outlined in the Bash-it Powerline documentation, you can use the hostname name to add the hostname to your Powerline prompt:
The contents of the prompt can be "reordered", all the "segments" (every piece of information) can take any place. The currently available segments are:
aws_profile- Show the current value of the AWS_PROFILE environment variablebattery- Battery information (you'll need to enable the battery plugin)clock- Current time in HH:MM:SS formatcwd- Current working directory including full folder hierarchy (c.f. wd)hostname- Host name of machinein_vim- Show identifier if running in :terminal from vimk8s_context- Show current kubernetes contextlast_status- Exit status of last run commandpython_venv- Python virtual environment information (virtualenv, venv and conda supported)ruby- Current ruby version if using rvmnode- Current node version (only nvm is supported)scm- Version control information, gituser_info- Current userwd- Working directory, like cwd but doesn't show the full folder hierarchy, only the directory you're currently in.shlvl- Show the current shell level (based on SHLVL environment variable), but only if you are not in root shelldirstack- Show the current dirstack level (based on DIRSTACK environment variable), but only if the stack is not emptyhistory_number- Show current history numbercommand_number- Show current command numberA variable can be defined to set the order of the prompt segments:
POWERLINE_PROMPT="user_info scm python_venv ruby cwd"
Based on this, you can add the hostname segment to the POWERLINE_PROMPT variable (e.g. in your Bash profile):
export POWERLINE_PROMPT="hostname user_info scm python_venv ruby cwd"
This will add the hostname as the first entry in the prompt.
There currently is no functionality in Bash-it to assign a random colour to the prompt segments.