Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve the git branch info details #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
improve the git branch info details
this patch use fish's `__fish_git_prompt` funciton to get more details
in a git repo, it improves the following:

1. show the commit instead of empty branch when checkout to a detached
commit
2. show the progress detail when doing rebase|merge|stash process
   eg. git rebase -i HEAD~3, then it will show the branch name with a
   rebase step such as "(master|REBASE-i1/3)"

Signed-off-by: Penghui Liao <[email protected]>
paco0x committed Sep 13, 2021
commit 295bdac1a6cc68f9b2a0d0dc71218009a538bca4
11 changes: 7 additions & 4 deletions functions/fish_prompt.fish
Original file line number Diff line number Diff line change
@@ -4,7 +4,9 @@
# set -g theme_display_git_untracked no

function _git_branch_name
echo (command git symbolic-ref HEAD 2> /dev/null | sed -e 's|^refs/heads/||')
echo (command git symbolic-ref HEAD 2> /dev/null; \
or command git rev-parse --short HEAD 2> /dev/null) \
| sed -e 's|^refs/heads/||'
end

function _is_git_dirty
@@ -32,9 +34,10 @@ function fish_prompt
end
set -l cwd $cyan(basename (prompt_pwd))

if [ (_git_branch_name) ]
set -l git_branch $red(_git_branch_name)
set git_info "$blue git:($git_branch$blue)"
if [ (__fish_git_prompt) ]
set -l branch_info (__fish_git_prompt | tr -d '() ')
set -l branch_info $red{$branch_info}
set git_info "$blue git:($branch_info$blue)"

if [ (_is_git_dirty) ]
set -l dirty "$yellow"