DEV Community

Discussion on: How to do twice as much with half the keystrokes using `.bashrc`

Collapse
 
brandonwallace profile image
brandon_wallace

This is the method I use to display the git branch I am currently working on.
I check for the existence of a .git folder, then I run the command git bash.
I also check to see in the virtual environment is enabled.

# Display the current branch.
function git_branch() {
    if [ -d .git ] ; then
        printf "%s" "($(git branch | awk '/\*/{print $2}'))";
    fi
}

# Check if the virtual environment is enabled.
function is_venv_enabled() {
    [ -z "$VIRTUAL_ENV" ] || printf "%s" "(venv)"
}

# Set the prompt.
function bash_prompt(){
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]$(git_branch)$(is_venv_enabled)\W \$ \[\033[00m\]'
}
Enter fullscreen mode Exit fullscreen mode