Skip to content

Instantly share code, notes, and snippets.

@shakeeb91
Created July 10, 2024 14:14
Show Gist options
  • Save shakeeb91/e82138995478d996f64932e5a8ffdb28 to your computer and use it in GitHub Desktop.
Save shakeeb91/e82138995478d996f64932e5a8ffdb28 to your computer and use it in GitHub Desktop.
BASH and GIT Setting

Introduction

All OS either on windows and linuxs has there desired user. You can set the profile and bash settings from a file named as ~/.bashrc or ~/.profile.

Windows

If you have installed BASH on your windows machine using WSL and want to beautify your git terminal you need to update the ~/.bashrc

Install gitprompt.sh

Download the git prompt script in home path.

curl -o ~/.git-prompt.sh https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh

Once it get downloaded, Here is the code you need to add in ~/.bashrc

# Git branch in prompt
source ~/.git-prompt.sh # make sure you have file present on this location.
GIT_PS1_SHOWCOLORHINTS=true
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWSTASHSTATE=true
GIT_PS1_SHOWUNTRACKEDFILES=true
GIT_PS1_SHOWUPSTREAM="auto"

# Customize prompt appearance with symbols
PS1='\[\e[32m\]\u@\h \[\e[34m\]\W\[\e[33m\]$(__git_ps1 " (\[\e[31m\]$(git_prompt_symbol dirty)\[\e[33m\]$(git_prompt_symbol staged)\[\e[33m\]$(git_prompt_symbol stash)\[\e[33m\]$(git_prompt_symbol branch)\[\e[33m\]%s)")\[\e[0m\]\$ '

# Define symbols for different Git states
GIT_PROMPT_SYMBOLS=(
    [clean]="✓"          # Clean working directory
    [dirty]="✗"          # Dirty working directory
    [untracked]="?"      # Untracked files
    [staged]="+"         # Staged changes
    [conflicted]="!"     # Conflicts
    [stash]="⚑"          # Stashed changes
    [branch]="➜"         # Branch symbol
)

# Function to return the appropriate symbol
git_prompt_symbol() {
    local state=$1
    echo -n "${GIT_PROMPT_SYMBOLS[$state]}"
}

output:

Here: shakeeb is username msh-notebook is computername devops is the directory updating_readme_file is the branchname

shakeeb@msh-notebook devops (➜➜➜ ➜ updating_readme_files *%)$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment