Git branch in the prompt
up vote
2
down vote
favorite
Could anyone explain why the branch name is not showing up on my (bash
) prompt?
I am using ubuntu 16.10. I tried to use the instructions from this site.
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*)/ (1)/'
}
export PS1="u@h W[33[32m]$(parse_git_branch)[33[00m] $ "
My .bashrc
file is here: https://github.com/JeremieGauthier/.bashrc/blob/master/.bashrc
I also tried the following code but it didn't work either.
function color_my_prompt {
local __user_and_host="[33[01;32m]u@h"
local __cur_location="[33[01;34m]w"
local __git_branch_color="[33[31m]"
#local __git_branch="`ruby -e "print (%x{git branch 2> /dev/null}.grep(/^*/).first || '').gsub(/^* (.+)$/, '(1) ')"`"
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\* (.+)$/(\\1) /`'
local __prompt_tail="[33[35m]$"
local __last_color="[33[00m]"
export PS1="$__user_and_host $__cur_location $__git_branch_color$__git_branch$__prompt_tail$__last_color "
}
color_my_prompt
bash rc
add a comment |
up vote
2
down vote
favorite
Could anyone explain why the branch name is not showing up on my (bash
) prompt?
I am using ubuntu 16.10. I tried to use the instructions from this site.
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*)/ (1)/'
}
export PS1="u@h W[33[32m]$(parse_git_branch)[33[00m] $ "
My .bashrc
file is here: https://github.com/JeremieGauthier/.bashrc/blob/master/.bashrc
I also tried the following code but it didn't work either.
function color_my_prompt {
local __user_and_host="[33[01;32m]u@h"
local __cur_location="[33[01;34m]w"
local __git_branch_color="[33[31m]"
#local __git_branch="`ruby -e "print (%x{git branch 2> /dev/null}.grep(/^*/).first || '').gsub(/^* (.+)$/, '(1) ')"`"
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\* (.+)$/(\\1) /`'
local __prompt_tail="[33[35m]$"
local __last_color="[33[00m]"
export PS1="$__user_and_host $__cur_location $__git_branch_color$__git_branch$__prompt_tail$__last_color "
}
color_my_prompt
bash rc
2
Rather thangit branch
(which is a porcelain command), you should useget rev-parse --abbrev-ref HEAD
to get the branch name. And if you stop discarding the error message you may see that perhaps you are not in a git working directory, soparse_git_branch
generates no output.
– William Pursell
Aug 30 '17 at 19:45
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Could anyone explain why the branch name is not showing up on my (bash
) prompt?
I am using ubuntu 16.10. I tried to use the instructions from this site.
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*)/ (1)/'
}
export PS1="u@h W[33[32m]$(parse_git_branch)[33[00m] $ "
My .bashrc
file is here: https://github.com/JeremieGauthier/.bashrc/blob/master/.bashrc
I also tried the following code but it didn't work either.
function color_my_prompt {
local __user_and_host="[33[01;32m]u@h"
local __cur_location="[33[01;34m]w"
local __git_branch_color="[33[31m]"
#local __git_branch="`ruby -e "print (%x{git branch 2> /dev/null}.grep(/^*/).first || '').gsub(/^* (.+)$/, '(1) ')"`"
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\* (.+)$/(\\1) /`'
local __prompt_tail="[33[35m]$"
local __last_color="[33[00m]"
export PS1="$__user_and_host $__cur_location $__git_branch_color$__git_branch$__prompt_tail$__last_color "
}
color_my_prompt
bash rc
Could anyone explain why the branch name is not showing up on my (bash
) prompt?
I am using ubuntu 16.10. I tried to use the instructions from this site.
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*)/ (1)/'
}
export PS1="u@h W[33[32m]$(parse_git_branch)[33[00m] $ "
My .bashrc
file is here: https://github.com/JeremieGauthier/.bashrc/blob/master/.bashrc
I also tried the following code but it didn't work either.
function color_my_prompt {
local __user_and_host="[33[01;32m]u@h"
local __cur_location="[33[01;34m]w"
local __git_branch_color="[33[31m]"
#local __git_branch="`ruby -e "print (%x{git branch 2> /dev/null}.grep(/^*/).first || '').gsub(/^* (.+)$/, '(1) ')"`"
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\* (.+)$/(\\1) /`'
local __prompt_tail="[33[35m]$"
local __last_color="[33[00m]"
export PS1="$__user_and_host $__cur_location $__git_branch_color$__git_branch$__prompt_tail$__last_color "
}
color_my_prompt
bash rc
bash rc
edited Nov 22 at 3:03
TT--
603723
603723
asked Aug 30 '17 at 19:34
user8364555
2
Rather thangit branch
(which is a porcelain command), you should useget rev-parse --abbrev-ref HEAD
to get the branch name. And if you stop discarding the error message you may see that perhaps you are not in a git working directory, soparse_git_branch
generates no output.
– William Pursell
Aug 30 '17 at 19:45
add a comment |
2
Rather thangit branch
(which is a porcelain command), you should useget rev-parse --abbrev-ref HEAD
to get the branch name. And if you stop discarding the error message you may see that perhaps you are not in a git working directory, soparse_git_branch
generates no output.
– William Pursell
Aug 30 '17 at 19:45
2
2
Rather than
git branch
(which is a porcelain command), you should use get rev-parse --abbrev-ref HEAD
to get the branch name. And if you stop discarding the error message you may see that perhaps you are not in a git working directory, so parse_git_branch
generates no output.– William Pursell
Aug 30 '17 at 19:45
Rather than
git branch
(which is a porcelain command), you should use get rev-parse --abbrev-ref HEAD
to get the branch name. And if you stop discarding the error message you may see that perhaps you are not in a git working directory, so parse_git_branch
generates no output.– William Pursell
Aug 30 '17 at 19:45
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
At installation git
comes with a git-prompt.sh that a bash function __git_ps1
to update the prompt.
The function is simple and add the current branch when you cd inside a git repo directory.
Just add a call to this function or another one available in your ps1
and make sure your .bashrc
or your .bash_profile
load the bash_completion
directory.
If your version of git doesn't include the git_prompt.sh
script manually download it and follow the instructions it provide.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
At installation git
comes with a git-prompt.sh that a bash function __git_ps1
to update the prompt.
The function is simple and add the current branch when you cd inside a git repo directory.
Just add a call to this function or another one available in your ps1
and make sure your .bashrc
or your .bash_profile
load the bash_completion
directory.
If your version of git doesn't include the git_prompt.sh
script manually download it and follow the instructions it provide.
add a comment |
up vote
2
down vote
At installation git
comes with a git-prompt.sh that a bash function __git_ps1
to update the prompt.
The function is simple and add the current branch when you cd inside a git repo directory.
Just add a call to this function or another one available in your ps1
and make sure your .bashrc
or your .bash_profile
load the bash_completion
directory.
If your version of git doesn't include the git_prompt.sh
script manually download it and follow the instructions it provide.
add a comment |
up vote
2
down vote
up vote
2
down vote
At installation git
comes with a git-prompt.sh that a bash function __git_ps1
to update the prompt.
The function is simple and add the current branch when you cd inside a git repo directory.
Just add a call to this function or another one available in your ps1
and make sure your .bashrc
or your .bash_profile
load the bash_completion
directory.
If your version of git doesn't include the git_prompt.sh
script manually download it and follow the instructions it provide.
At installation git
comes with a git-prompt.sh that a bash function __git_ps1
to update the prompt.
The function is simple and add the current branch when you cd inside a git repo directory.
Just add a call to this function or another one available in your ps1
and make sure your .bashrc
or your .bash_profile
load the bash_completion
directory.
If your version of git doesn't include the git_prompt.sh
script manually download it and follow the instructions it provide.
edited Aug 31 '17 at 12:23
answered Aug 30 '17 at 19:57
lee-pai-long
71848
71848
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f45968420%2fgit-branch-in-the-prompt%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Rather than
git branch
(which is a porcelain command), you should useget rev-parse --abbrev-ref HEAD
to get the branch name. And if you stop discarding the error message you may see that perhaps you are not in a git working directory, soparse_git_branch
generates no output.– William Pursell
Aug 30 '17 at 19:45