From ebeb4737fdb850fb5bf00ed6e6d5b91c5b6d04ae Mon Sep 17 00:00:00 2001 From: Shervin Sahba Date: Mon, 28 Oct 2019 20:50:38 -0700 Subject: [PATCH 1/4] Updated git.py - branch name truncation options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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". --- powerline_shell/segments/git.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/powerline_shell/segments/git.py b/powerline_shell/segments/git.py index de2b049e..0d433f88 100644 --- a/powerline_shell/segments/git.py +++ b/powerline_shell/segments/git.py @@ -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: From 1ea649e2a874f418cd3971e9cf591e1df26122d8 Mon Sep 17 00:00:00 2001 From: Shervin Sahba Date: Mon, 28 Oct 2019 20:54:38 -0700 Subject: [PATCH 2/4] Update README.md - Added git config options --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index e6295711..fd4ca815 100644 --- a/README.md +++ b/README.md @@ -309,6 +309,11 @@ The `vcs` segment provides one option: - `show_symbol`: If `true`, the version control system segment will start with a symbol representing the specific version control system in use in the current directory. + +The options for the `git` segment are: + +- `master_is_M`: If `true`, the master branch will be abbreviated to M. +- `branch_max_length`: Maximum number of characters displayed for the branch name. The options for the `battery` segment are: From 8edea0455dda1125a5b8f4bc8052354104c5b072 Mon Sep 17 00:00:00 2001 From: Shervin Sahba Date: Mon, 28 Oct 2019 20:58:02 -0700 Subject: [PATCH 3/4] Fixed redundant assignment typo --- powerline_shell/segments/git.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerline_shell/segments/git.py b/powerline_shell/segments/git.py index 0d433f88..3591fea7 100644 --- a/powerline_shell/segments/git.py +++ b/powerline_shell/segments/git.py @@ -75,7 +75,7 @@ def run(self): # 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' + self.branch = self.branch[:branch_max_length] + u'\u2026' def add_to_powerline(self): self.join() From e68c9987992567ba23d365130f2d402c5a5786e1 Mon Sep 17 00:00:00 2001 From: Shervin Sahba Date: Mon, 28 Oct 2019 22:08:51 -0700 Subject: [PATCH 4/4] Update git.py - added a check to see if branch exists Forgot to check if a branch existed! Fixed that. Now the script works in both .git repos and other directories. --- powerline_shell/segments/git.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/powerline_shell/segments/git.py b/powerline_shell/segments/git.py index 3591fea7..435e0b01 100644 --- a/powerline_shell/segments/git.py +++ b/powerline_shell/segments/git.py @@ -67,15 +67,17 @@ 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" + if self.branch: + # 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[:branch_max_length] + u'\u2026' + # 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[:branch_max_length] + u'\u2026' + def add_to_powerline(self): self.join()