Skip to content

Instantly share code, notes, and snippets.

@AlexandroPerez
Last active June 15, 2018 08:59
Show Gist options
  • Save AlexandroPerez/188dd7d5d7546009fb3c101837cb97f2 to your computer and use it in GitHub Desktop.
Save AlexandroPerez/188dd7d5d7546009fb3c101837cb97f2 to your computer and use it in GitHub Desktop.
Cygwin and WSL colored bash prompt that shows current git branch if the folder is a git repo.
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1]/'
}
# NOTE: The dollar sign ($) has to be escaped so that the above function is executed every time the prompt is shown
# like this: \$(git_branch)
export PS1="\[\e]0;\w\a\]\n\[\e[36m\]CygWin:\[\e[33m\]\w\[\e[0m\] \[\e[32m\]\[\e[1m\]\$(git_branch)\[\e[0m\]\n$ "
# For WSL
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1]/'
}
# NOTE: The dollar sign ($) has to be escaped so that the above function is executed every time the prompt is shown
# like this: \$(git_branch)
export PS1="\[\e]0;\w\a\]\n\[\e[36m\]Bash:\[\e[33m\]\w\[\e[0m\] \[\e[35m\]\[\e[1m\]\$(git_branch)\[\e[0m\]\n$ "
# Change the way folders are displayed in terminal (green text green background) to just a teal text color)
LS_COLORS="ow=01;36;40" && export LS_COLORS
@AlexandroPerez
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment