Hey guys. It's AC Alexandre Calaça here. How have you been?
The goal of this article is to demonstrate how to include current git branch and path into bash prompt.
This article is tested in Debian based linux distributions.
This is my current OS.
Output is something like this:
Open bash configuration
Open your file management tool and open
CTRL+H and open the file .bashrc.
Include the following commands
export PS1="\u@\h \[\e[32m\]\w \[\e[91m\]\$(parse_git_branch)\[\e[00m\]$ "
The previous command defines a new value for the environment variable PS1, which controls the format of the command prompt.
To be more specific, let's take a look at each part:
\uexpands to the username of the current user.
\hexpands to the hostname of the machine.
\[\e[91m\]are ANSI escape sequences that set the text color to green and red, respectively.
\wexpands to the current working directory.
$(parse_git_branch)is a command substitution that calls the
parse_git_branchfunction to display the current Git branch name.
\[\e[00m\]is an ANSI escape sequence that resets the text color to the default.
IT worked like a charm!!
The article showed how to include current git branch and path into bash prompt in Deepin OS 20.7 and any other Debian based linux distributions.
That's all for today. Thanks for reading the article
How to show current git branch with colors in Bash prompt in Deepin OS and any other Debian based linux distributions.
I hope this article helped you. Let me know if you have any questions.
Your thoughts, suggestions and corrections are more than welcome.
By the way, feel free to drop your suggestions on new blog articles.
Hope to see you next time.