TIP: Prompt Magic - Colorizing your shell prompt
Welcome to the world of Unix and Linux, where geeks and hackers rule the roost. If you’ve just joined us, you might find the command prompt a bit… well, let’s say “monochrome”. It can be anything from a plain black-on-white to a washed-out gray on blah background. And it’s the same for all Unix-like systems, be it Ubuntu, CentOS, MacOS, or any other.
Shell Prompt Colorization
Now, let’s face it. Sometimes, a colored prompt can make the black-and-white world of Unix and Linux just a little more…colorful! It not only adds a personal touch to your console, but also can serve as a quick and easy way to identify the type of server or client you’re connected to.
The Benefits of Shell Prompt Colorization
- Easier Identification: With different colors for different types of servers or clients, it’s much easier to identify them at a glance.
- Distraction-free Console: Color coding your console can reduce distractions by highlighting important information and messages.
- Customizability: You can choose the colors and patterns that please you the most, adding a personal touch to your console experience.
- Increased Productivity: Some color schemes make it easy to spot important information or errors, which can help you work more efficiently.
- Fun Factor: OK, this might be a bit subjective, but having a colored prompt can just make using the console more fun!
How to Get Started with Shell Prompt Colorization
The good news is that getting started with shell prompt colorization is pretty easy. Here’s what you need to do: - Pick a color scheme: Start by choosing a color scheme that you like. You can either go for something pre-defined or create your own. There are several resources online that provide ready-to-use color schemes for your shell prompt.
- Install the necessary tools: Depending on the type of Unix/Linux system you’re using, you might need to install some packages or tools for customizing your prompt. For example, on Ubuntu/Debian-based systems, you might need to install the
bash-it package. On CentOS/Fedora-based systems, you might need to install the oh-my-bash package. - Customize your prompt: Once you have the necessary tools installed, you can proceed to customize your prompt. This typically involves modifying a hidden file in your home directory called
.bashrc or .bash_profile. Open this file using a text editor and add the necessary code to set your desired color scheme for your prompt. - Source the file: After saving your changes, you need to source the file so that the changes take effect immediately. You can do this by running the command
source ~/.bashrc (or .bash_profile). - Voila!: Once you’ve sourced the file, you should see your new colored prompt in action!
Example: Using Bash-it on Ubuntu/Debian
- Install
bash-it:sudo apt updatesudo apt install bash-it
- Customize your prompt:
- Open the hidden file
.bashrc in your home directory using a text editor:nano ~/.bashrc
- Add the following code at the end of the file (replace
YOUR_USERNAME with your actual username):
bash
source /etc/bash_it/plugins/available/vi-mode.plugin.bash
source /etc/bash_it/plugins/available/completed_projects.plugin.bash
PS1="\[\033[36m\]YOUR_USERNAME@localhost \[\033[0m\]"$(__git_ps1 " (%s)")$ "\[\033[32m\]\w\[\033[0m\]"$(date +%T)\]$ "\[\033[0m\]" "\[\033[1;31m\]→\[\033[0m\] " 2. Press Ctrl+X, then type Y to save the changes and exit the editor. Next, you need to source the file to make the changes take effect. Run the following command: Run the following command: `bashsource ~/.bashrc`` Press enter and you’re done! You should now see your new