mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-30 04:21:19 -08:00
feat(git): add symbol to the branch name when truncating
This commit is contained in:
parent
f58567e015
commit
bcdfb8180b
|
@ -76,6 +76,7 @@ You can set the following properties to `true` to enable fetching additional inf
|
|||
- branch_behind_icon: `string` - the icon to display when the local branch is behind its remote - defaults to `\u2193`
|
||||
- branch_gone_icon: `string` - the icon to display when there's no remote branch - defaults to `\u2262`
|
||||
- branch_max_length: `int` - the max length for the displayed branch name where `0` implies full length - defaults to `0`
|
||||
- truncate_symbol: `string` - the icon to display when a branch name is truncated - defaults to empty
|
||||
|
||||
#### HEAD
|
||||
|
||||
|
|
|
@ -95,6 +95,8 @@ const (
|
|||
|
||||
// BranchMaxLength truncates the length of the branch name
|
||||
BranchMaxLength Property = "branch_max_length"
|
||||
// TruncateSymbol appends the set symbol to a truncated branch name
|
||||
TruncateSymbol Property = "truncate_symbol"
|
||||
// BranchIcon the icon to use as branch indicator
|
||||
BranchIcon Property = "branch_icon"
|
||||
// BranchIdenticalIcon the icon to display when the remote and local branch are identical
|
||||
|
@ -384,7 +386,8 @@ func (g *git) truncateBranch(branch string) string {
|
|||
if maxLength == 0 || len(branch) < maxLength {
|
||||
return branch
|
||||
}
|
||||
return branch[0:maxLength]
|
||||
symbol := g.props.getString(TruncateSymbol, "")
|
||||
return branch[0:maxLength] + symbol
|
||||
}
|
||||
|
||||
func (g *git) hasGitFile(file string) bool {
|
||||
|
|
|
@ -667,6 +667,34 @@ func TestTruncateBranch(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTruncateBranchWithSymbol(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Expected string
|
||||
Branch string
|
||||
MaxLength interface{}
|
||||
TruncateSymbol interface{}
|
||||
}{
|
||||
{Case: "No limit", Expected: "all-your-base-are-belong-to-us", Branch: "all-your-base-are-belong-to-us", TruncateSymbol: "..."},
|
||||
{Case: "No limit - larger", Expected: "all-your-base...", Branch: "all-your-base-are-belong-to-us", MaxLength: 13.0, TruncateSymbol: "..."},
|
||||
{Case: "No limit - smaller", Expected: "all-your-base", Branch: "all-your-base", MaxLength: 16.0, TruncateSymbol: "..."},
|
||||
{Case: "Invalid setting", Expected: "all-your-base", Branch: "all-your-base", MaxLength: "burp", TruncateSymbol: "..."},
|
||||
{Case: "Lower than limit", Expected: "all-your-base", Branch: "all-your-base", MaxLength: 20.0, TruncateSymbol: "..."},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
g := &git{
|
||||
props: &properties{
|
||||
values: map[Property]interface{}{
|
||||
BranchMaxLength: tc.MaxLength,
|
||||
TruncateSymbol: tc.TruncateSymbol,
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.Equal(t, tc.Expected, g.truncateBranch(tc.Branch), tc.Case)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetGitCommand(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
|
|
Loading…
Reference in a new issue