Skip to content

Instantly share code, notes, and snippets.

@giner
Created January 30, 2025 03:44
Show Gist options
  • Save giner/e9f6ac7c7d4e160d658538b214c81d55 to your computer and use it in GitHub Desktop.
Save giner/e9f6ac7c7d4e160d658538b214c81d55 to your computer and use it in GitHub Desktop.
Add Git info to Bash prompt
#!/bin/bash
set -eu
# Add Git info to Bash prompt
bash_prompt_configuration=(
'PS1="${PS1%\\$ }\$(__git_ps1)\\$ "'
'GIT_PS1_SHOWDIRTYSTATE=1'
)
for conf in "${bash_prompt_configuration[@]}"; do
if ! grep -qxF "$conf" ~/.bashrc; then
echo "$conf" >> ~/.bashrc
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment