Last active
October 9, 2019 05:42
-
-
Save grese/a101913c00cc2120bd0d0cd4e9a6359f to your computer and use it in GitHub Desktop.
Automatic git bash prompt setup for MacOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#======================================= | |
# git-prompt-setup.sh | |
# | |
# Adds git branch to your bash prompt. | |
#======================================= | |
GITPROMPT_DIR=~/.bin | |
GITPROMPT_FILE=git-prompt.sh | |
GITPROMPT_URL=https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh | |
BASH_PROFILE_FILE=~/.bash_profile | |
# Fetch and save the git-prompt shell script | |
mkdir -p $GITPROMPT_DIR | |
curl -o $GITPROMPT_DIR/$GITPROMPT_FILE $GITPROMPT_URL | |
# Write the new prompt to bash profile | |
cat > $BASH_PROFILE_FILE <<- EOM | |
#### Git Prompt #### | |
PS1='\h:\W \u$(__git_ps1 "(%s)")\$' | |
EOM | |
# Update the prompt: | |
source ~/.bash_profile | |
echo "Your prompt has been updated. To modify the prompt, edit the PS1 variable in ~/.bash_profile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description:
Automatically modifies your bash prompt to include the current git branch of your current working directory.
When inside a git repository, the format of the prompt will be
user@host:directory(branch)$
. When not in a git repo, the prompt will beuser@host:directory$
Usage:
$
./git-prompt-setup.sh
NOTE: this script could easily be modified to work for bash on any OS just by changing the "BASH_PROFILE_FILE" variable.