arl/gitmux

feature-request: truncate long branch names

cdelledonne opened this issue · 11 comments

Hi, I was wondering if you would consider adding a configuration option to allow the user to truncate (and up to how much) long branch names. I encountered some very long branch names, which don't fit in my status bar when on a small screen (e.g. a laptop).

Cheers!

arl commented

Hey!
This has definitely been on my list of features to add to gitmux!

I think limiting the whole gitmux string can already be performed with some tmux format strings magic, but that's not what you meant I guess since this would not trim the branch part, but whatever section lies at the extremity, so yes, not useful.

That's why we should do it in gitmux.
What do you think of a simple config entry like branch_max_length or something?

arl commented

Labelling this as good first issue in case you, @cdelledonne , or anybody, want to give it a try.
It's a pretty simple feature to add.
If in some days nobody has came up with anything, I'm gonna do it

Something like branch_max_length could work. Where would you add it? As a new key, or under one of styles or layout?

Alternatively, I had also thought of appending the max length to the layout component, e.g.

layout: [branch:40, '..', remote, ' - ', flags]

would specify "40" as the max length.

Should remote-branch and remote also allow a max length?

arl commented

My idea was that to place the new branch_max_len key under the styles section.

If no value has been set in config YAML, thid will be converted to 0 on the Go side, which means setting it explicitly to 0 is the same as not setting it and would correspond to current behaviour, i.e no limit on the branch name. This is important to not break current users config

Placing the max length as :40 would make parsing slightly more complicate and I'd prefer to keep it dead simple.

To answer to your last question:
I think there should only be one single limit, but that limit would apply for the branch name in both the local and remote.
For example, if the limit is set to 5 and my local branch name is my-branch which is tracking origin/my-branch, then layout.branch would be shown as my-br and layout.remote would be trimmed to origin/my-br. I think it's better that the limit does not apply to the name of the remote itself (i.e origin).

Does that make sense?

Placing the max length as :40 would make parsing slightly more complicate and I'd prefer to keep it dead simple.

ACK.

My idea was that to place the new branch_max_len key under the styles section.

In my opinion, this feels a little unintuitive from a user's perspective, since all of the styles entries are tmux style format strings, as also mentioned in the README. However, adding a new key under tmux looks odd too :).

I think there should only be one single limit, but that limit would apply for the branch name in both the local and remote.

Sounds good.

arl commented

In my opinion, this feels a little unintuitive from a user's perspective, since all of the styles entries are tmux style format strings, as also mentioned in the README. However, adding a new key under tmux looks odd too :).

Yeah you're right, it's probably better to keep it that way (only tmux format strings under styles).
Same for adding it under tmux, and under symbols has no sense.
Also layout is a yaml list representing the overall layout of the gitmux status string, so..not there
😄 I guess that doesn't let us a lot of options, maybe we could add a new section, with a general enough name that we'll be able to reuse it later to stuff other config options:
extra or settings come to mind, I'm open to suggestions though

settings or options sounds good, good point about reusability for other config options.

I've never written Go, but I'd be happy to give it a try and prepare a PR this week. Would that be ok?

arl commented

settings or options sounds good, good point about reusability for other config options.

Great, let's go for options then!

I've never written Go, but I'd be happy to give it a try and prepare a PR this week. Would that be ok?

Sure, be my guest! That's awesome!
Happy to review when you're ready and/or answer questions.

So to sum it up:

  • a new options section
  • branch_max_len entry under that section
  • default value of 0 means no limit
  • when set, limit applies to the branch part in both the local and the remote branch names
  • About testing: there's a test named TestOutputNonRegression that checks that when gitmux is called with a default configuration the displayed string is stable, you shouldn't have to modify that test, just telling you since it might prove useful.

Other than that It'd be great if the new feature was tested, either a new test case or a new test entirely.
You can easily copy-paste existing test and change test inputs/outputs.
The code base is relatively small and Go is a very easy language!

Thanks again, cheers!

Thanks a lot! :)

arl commented

Going to create a v0.7.0. That was a very neat PR you submitted for somebody that never did Go before.
Looking forward to many more ;-)

Glad to contribute, and until next time :).