Support for Git default branches other than master (#276)

* Make main behave like master branch
* Check list of default git branches
* Use new theme var with better name
* Update documentation around git default branch names
pull/282/head
Darren Kidd 4 years ago committed by GitHub
parent 64366ed658
commit 57d172882f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -74,7 +74,8 @@ set -g theme_display_git_untracked no
set -g theme_display_git_ahead_verbose yes
set -g theme_display_git_dirty_verbose yes
set -g theme_display_git_stashed_verbose yes
set -g theme_display_git_master_branch yes
set -g theme_display_git_default_branch yes
set -g theme_git_default_branches master main
set -g theme_git_worktree_support yes
set -g theme_use_abbreviated_branch_name yes
set -g theme_display_vagrant yes
@ -108,6 +109,10 @@ set -g theme_project_dir_length 1
set -g theme_newline_cursor yes
set -g theme_newline_prompt '$ '
```
**Git options**
- `theme_display_git_default_branch`. By default theme will hide/collapse the branch name in your prompt when you are using a Git _default branch_ i.e. historically `master` and often `main` now. Set to `yes` to stop these branches from being hidden/collapsed.
- `theme_git_default_branches`. The big cloud repos (GitHub, Bitbucket, GitLab et al.) are moving away from using `master` as the default branch name, and allow you to choose your own. As of version **2.28**, Git also supports custom default branch names via the `init.defaultBranch` config option. If our defaults of `master main` don't suit you, you can add/remove names in thist list i.e. `main trunk`. This ensures correct hiding/collapsing behaviour with custom default branch names (unless option above is activated).
**Title options**

@ -23,7 +23,8 @@
# set -g theme_display_git_ahead_verbose yes
# set -g theme_display_git_dirty_verbose yes
# set -g theme_display_git_stashed_verbose yes
# set -g theme_display_git_master_branch yes
# set -g theme_display_git_default_branch yes
# set -g theme_git_default_branches main trunk
# set -g theme_git_worktree_support yes
# set -g theme_display_vagrant yes
# set -g theme_display_docker_machine no
@ -77,18 +78,22 @@ function __bobthefish_escape_regex -a str -d 'A backwards-compatible `string esc
end
function __bobthefish_git_branch -S -d 'Get the current git branch (or commitish)'
set -l ref (command git symbolic-ref HEAD 2>/dev/null)
set -l branch (command git symbolic-ref HEAD | string replace -r '^refs/heads/' '' 2>/dev/null)
and begin
[ "$theme_display_git_master_branch" != 'yes' -a "$ref" = 'refs/heads/master' ]
[ -n "$theme_git_default_branches" ]
or set -l theme_git_default_branches master main
[ "$theme_display_git_master_branch" != 'yes' -a "$theme_display_git_default_branch" != 'yes' ]
and contains $branch $theme_git_default_branches
and echo $branch_glyph
and return
# truncate the middle of the branch name, but only if it's 25+ characters
set -l truncname $ref
set -l truncname $branch
[ "$theme_use_abbreviated_branch_name" = 'yes' ]
and set truncname (string replace -r '^(.{28}).{3,}(.{5})$' "\$1…\$2" $ref)
and set truncname (string replace -r '^(.{17}).{3,}(.{5})$' "\$1…\$2" $branch)
string replace -r '^refs/heads/' "$branch_glyph " $truncname
echo $branch_glyph $truncname
and return
end

Loading…
Cancel
Save