Updated git.py - branch name truncation options

Two config.json options added that help truncate git branch names. The first shortens "master" to "M". The second truncates the branch name to a given length. For example, with these config settings:
```
  "git": {
      "master_is_M": true,
      "branch_max_length": 5
}
```
We would see "M" in lieu of "master" and "whate…" in lieu of "whatever".
This commit is contained in:
Shervin Sahba 2019-10-28 20:50:38 -07:00 committed by GitHub
parent a9b8c9bb39
commit ebeb4737fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -66,7 +66,17 @@ def build_stats():
class Segment(ThreadedSegment):
def run(self):
self.stats, self.branch = build_stats()
# Abbreviates master branch to M
if self.powerline.segment_conf("git", "master_is_M"):
if self.branch == "master":
self.branch = "M"
# Truncates branch length
branch_max_length = self.powerline.segment_conf("git", "branch_max_length", -1)
if len(self.branch) > branch_max_length :
self.branch = self.branch = self.branch[:branch_max_length] + u'\u2026'
def add_to_powerline(self):
self.join()
if not self.stats: