Cuando abres por primera vez la aplicación de terminal, recibes un aviso que informa sobre el nombre de usuario, el nombre de máquina y otra información, como el directorio actual.
Ese mensaje se muestra en un texto blanco sin formato.
Sin embargo, en Manjaro Linux, el equipo de desarrollo de Manjaro modifica el indicador para que parezca más agradable. Sin embargo, no puedes modificar nada sobre la interfaz (color, etc.).
En este artículo, vamos a ver cómo se puede colorear el indicador de bash fácilmente incluyendo modificaciones simples de bashrc.
Comprueba qué Shell estás utilizando
De forma predeterminada, por lo general, todas las distribuciones principales incluyen Bash pero puede ser diferente en tu distribución de Linux o si has instalado una nueva shell como FISH o KSH.
Para identificar el shell en uso, simplemente abre una Terminal y escribe:
ps $$
La salida simplemente mostrará la información sobre qué shell está utilizando actualmente.
Haz una copia de seguridad de tus archivos BahsRC / FishRC / ZhRC
Es importante hacer una copia de seguridad de los archivos antiguos, en caso de que arruines algo y el sistema comience a comportarse de manera anormal.
Para hacer esto en tu shell (por ejemplo, ZhRC, FishRC, etc.), escribe los comandos de la siguiente manera:
cp .bashrc bash .bak
O el siguiente comando para ZhRC
cp .zshrc zsh.bak
De manera similar para K Shell:
cp .kshrc ksh.bak
Modifica tu archivo Bash
Abre el archivo .bashrc (o tu archivo de shell) usando tu editor de texto preferido, como Nano o Vim. Simplemente escribe:
nano .bashrc
O si estás utilizando Vim Text Editor:
vim .bashrc
Luego, navega hasta la parte inferior y agrega el siguiente script:
# Original Author: Caesar Kabalan
# Modifications : Aadesh
# Where:
# CWD - Current working directory (green if last command returned 0, red otherwise)
# COUNT - Session command count
# BRANCH - Current git branch if in a git repository, omitted if not in a git repo
# VENV - Current Python Virtual Environment if set, omitted if not set
# USER - Current username
# HOSTNAME - System hostname
function set_bash_prompt () {
# Color codes for easy prompt building
COLOR_DIVIDER="\[\e[30;1m\]"
COLOR_CMDCOUNT="\[\e[36;1m\]"
COLOR_USERNAME="\[\e[33;1m\]"
COLOR_DIVIDER="\[\e[31;1m\]"
COLOR_USERHOSTAT="\[\e[31;1m\]"
COLOR_HOSTNAME="\[\e[33;1m\]"
COLOR_GITBRANCH="\[\e[33;1m\]"
COLOR_VENV="\[\e[33;1m\]"
COLOR_GREEN="\[\e[32;1m\]"
COLOR_PATH_OK="\[\e[32;1m\]"
COLOR_PATH_ERR="\[\e[31;1m\]"
COLOR_NONE="\[\e[0m\]"
# Change the path color based on return value.
if test $? -eq 0 ; then
PATH_COLOR=${COLOR_PATH_OK}
else
PATH_COLOR=${COLOR_PATH_ERR}
fi
# Set the PS1 to be "[workingdirectory:commandcount"
PS1="${COLOR_DIVIDER}[${PATH_COLOR}\w${COLOR_DIVIDER}:${COLOR_CMDCOUNT}\#${COLOR_DIVIDER}"
# Add git branch portion of the prompt, this adds ":branchname"
if ! git_loc="$(type -p "$git_command_name")" || [ -z "$git_loc" ]; then
# Git is installed
if [ -d .git ] || git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
# Inside of a git repository
GIT_BRANCH=$(git symbolic-ref --short HEAD)
PS1="${PS1}:${COLOR_GITBRANCH}${GIT_BRANCH}${COLOR_DIVIDER}"
fi
fi
# Add Python VirtualEnv portion of the prompt, this adds ":venvname"
if ! test -z "$VIRTUAL_ENV" ; then
PS1="${PS1}:${COLOR_VENV}`basename \"$VIRTUAL_ENV\"`${COLOR_DIVIDER}"
fi
# Close out the prompt, this adds "]\n[username@hostname] "
PS1="${PS1}]\n${COLOR_DIVIDER}[${COLOR_USERNAME}\u${COLOR_USERHOSTAT}@${COLOR_HOSTNAME}\h${COLOR_DIVIDER}]${COLOR_NONE} "
}
# Tell Bash to run the above function for every prompt
export PROMPT_COMMAND=set_bash_prompt
# tab completion
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
# use colours in the prompt
[[ -f ~/.dir_colors ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
[[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(/dev/null \
&& match_lhs=$(dircolors --print-database)
if [[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] ; then
if type -P dircolors >/dev/null ; then
if [[ -f ~/.dir_colors ]] ; then
eval $(dircolors -b ~/.dir_colors)
elif [[ -f /etc/DIR_COLORS ]] ; then
eval $(dircolors -b /etc/DIR_COLORS)
fi
fi
PS1="$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]\h'; else echo '\[\033[01;32m\]\u@\h'; fi)\[\033[01;34m\] \w \$([[ \$? != 0 ]] && echo \"\[\033[01;31m\]:(\[\033[01;34m\] \")\\$\[\033[00m\] "
else
PS1="\u@\h \w \$([[ \$? != 0 ]] && echo \":( \")\$ "
fi
Una vez que hayas pegado el código, simplemente presiona Ctrl + O si estás usando el editor de texto Nano para guardar el archivo y presiona Ctrl + X para salir.
Si estás usando Vim, escribe :wq y presiona enter para guardar y salir.
Finalmente, vuelve a cargar el bash para que reconozca las modificaciones recientes:
source .bashrc
También puedes cambiar los colores si no te gustaron los colores con los que se agrego con el script, puedes utilizar la tabla de códigos ANSI para los colores.