12 lines
557 B
Bash
12 lines
557 B
Bash
# Function to parse and display the current Git branch
|
|
parse_git_branch() {
|
|
# Check if inside a Git repository, suppress errors (2>/dev/null)
|
|
# Get branch list, filter for the line starting with '*', and remove the first two characters '* '
|
|
git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
|
|
}
|
|
|
|
# Define your custom PS1
|
|
# The format is: [Green]user@host [Blue]pwd[Yellow] (git-branch)[Default]$
|
|
export PS1="\\[\\033[01;32m\\]\\u@\\h\\[\\033[0m\\]:\\[\\033[01;34m\\]\\w\\[\\033[0;33m\\]\$(parse_git_branch)\\[\\033[0m\\]\\$ "
|
|
|