Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config options added to truncate git branch names #482

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
12 changes: 12 additions & 0 deletions powerline_shell/segments/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@ def build_stats():
class Segment(ThreadedSegment):
def run(self):
self.stats, self.branch = build_stats()

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'


def add_to_powerline(self):
self.join()
if not self.stats:
Expand Down