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

Added truncation_length/symbol to git_branch #268

Merged
merged 2 commits into from Sep 2, 2019
Merged

Added truncation_length/symbol to git_branch #268

merged 2 commits into from Sep 2, 2019

Conversation

tivervac
Copy link
Contributor

Added a way to truncate git branches

Description

Git branches can become very long (e.g. gitlab auto-generated branch
names), thus it would be nice to be able to truncate them to keep your
prompt lenght in line.

This patch adds two new options to the git_branch module:

  • truncation_length: The amount of graphemes to of a gitbranch to
    truncate to
  • truncation_symbol: The symbol that should be used to indicate that a
    branch name was trunctated

To be able to correctly work with UTF-8 graphemes, unicode-segmentation
was added as a dependency.

Motivation and Context

I made this change because we use GitLab, but it's useful in other scenarios as well. If you have an issue on GitLab you can press a button on that issue to automatically create a merge request and a branch for you. However, the pattern for the branch name is ${ticket_nr}_${title}.toLowercase().replaceAll(" ", "_").

For issue number 1234 and title #1234 "Fix the typo in the about page when you right click something" we get a branch named 1234_fix_the_typo_in_the_about_page_when_you_right_click_something. Having this in your prompt makes it unusable as it uses up way too much space

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Screenshots (if appropriate):

Screenshot 2019-08-31 at 19 19 23

How Has This Been Tested?

  • I have tested using MacOS
  • I have tested using Linux
  • I have tested using Windows

I think I have a pretty complete testsuite, however I didn't test on any other OS's.

Checklist:

  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.

I updated the documentation, but I didn't know how to build it locally so I haven't checked that it's rendered as expected.

Git branches can become very long (e.g. gitlab auto-generated branch
names), thus it would be nice to be able to truncate them to keep your
prompt lenght in line.

This patch adds two new options to the git_branch module:
* truncation_length: The amount of graphemes to of a gitbranch to
truncate to
* truncation_symbol: The symbol that should be used to indicate that a
branch name was trunctated

To be able to correctly work with UTF-8 graphemes, unicode-segmentation
was added as a dependency.
Copy link
Member

@matchai matchai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! 👍
Thank you for adding this new configuration option.


// TODO: Once error handling is implemented, warn the user if their config
// truncation length is nonsensical
let len = if unsafe_truncation_length <= 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -0,0 +1,168 @@
use ansi_term::Color;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking the time to add extensive grapheme testing here! 🚀

@matchai matchai merged commit 59e8b1f into starship:master Sep 2, 2019
@matchai
Copy link
Member

matchai commented Sep 3, 2019

@all-contributors Please add @tivervac for code and test. 🎉

@allcontributors
Copy link
Contributor

@matchai

I've put up a pull request to add @tivervac! 🎉

@tivervac tivervac deleted the truncate_git_branch branch September 3, 2019 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants