Power User: 10 Customized Bash Prompts that you can use to Enhance your Linux Experience
Customizing your bash prompt can make your command line interface more informative, visually appealing, and helpful, especially during long coding sessions or while managing multiple servers.
Here’s a list of 10 customized bash prompts that you can use to enhance your Linux experience:
1. Simple Prompt with Full Path
Shows the full directory path in the prompt.
PS1='\[\e[1;34m\]\w\[\e[0m\] $ '
2. User and Host Information
Displays your username and hostname, useful for those who work with multiple machines.
PS1='\[\e[0;32m\]\u@\h\[\e[0m\]:\w$ '
3. Prompt with Git Branch
Shows the current branch in a git repository directory.
PS1='\[\e[1;32m\]\u@\h:\[\e[1;34m\]\w\[\e[0;33m\]$(git branch 2>/dev/null | grep "^*" | colrm 1 2)\[\e[0m\]$ '
4. Time-stamped Prompt
Includes the current time which can be useful for logging and understanding when commands were executed.
PS1='\[\e[0;34m\][\A]\[\e[0m\] \w$ '
5. Multiline Prompt
Keeps the command line clean by placing the prompt on a new line.
PS1='\[\e[1;32m\]\u@\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\]\n$ '
6. Color-coded Prompt for Root
Changes color if the user is root, which helps in avoiding accidental commands as superuser.
PS1='\[\e[1;31m\]\u@\h:\w$ \[\e[0m\]'
7. Exit Status of Last Command
Displays the exit status of the last command, which can be very useful for debugging.
PS1='[\$?] \[\e[0;32m\]\u@\h:\w\[\e[0m\]$ '
8. Prompt with Terminal Title
Sets the terminal title to the current directory, helpful for identifying terminal tabs.
PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\$ '
9. Dynamic Coloring Based on User
Changes the prompt color based on whether you are a regular user or root.
PS1='$(if [[ ${EUID} == 0 ]]; then echo "\[\e[1;31m\]\h"; else echo "\[\e[1;32m\]\u@\h"; fi)\[\e[0m\]:\w$ '
10. Enhanced Readability with Bold and Colors
Improves readability with bold text and multiple colors, making it easier to distinguish different parts of the prompt.
PS1='\[\e[1;37m\]\[\e[44m\]\u@\h \[\e[42m\] \w \[\e[0;35m\]$(git branch 2>/dev/null | grep "^*" | colrm 1 2)\[\e[0m\] $ '
To use any of these prompts, add the corresponding PS1
line to your ~/.bashrc
file. After adding, apply the changes with the command source ~/.bashrc
. Customizing your prompt can not only boost your productivity but also help avoid mistakes and make your terminal interface much more personal and suited to your workflow.