Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Add "truncate_with_folder_marker" shorten strategy #398

Merged
merged 10 commits into from
Feb 14, 2017

Conversation

dritter
Copy link
Member

@dritter dritter commented Feb 5, 2017

This adds @BenoitAverty truncate_with_folder_marker strategy for the dir segment.


zero='%([BSUbfksu]|([FB]|){*})'
current_path=$current_path${PWD:${#${(S%%)last_marked_folder//$~zero/}}}
;;
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't really know what I was doing with this function. The "loop" technique works but I'm not sure what effet it has on performance. Maybe someone with a stronger knowledge of bash or zsh can optimize it later...

Copy link
Member

Choose a reason for hiding this comment

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

@dritter @BenoitAverty - What are your thoughts on Benoit's comment, here? Do you want to iterate on this function or should we merge as-is?

Copy link
Member Author

Choose a reason for hiding this comment

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

@bhilburn Thanks for pointing me to this again. This is a quite complicated pattern to count the visible characters in the prompt. In our case we count the characters in $last_marked_folder (which should not contain any non-visible characters) and replace the amount of characters in $PWD from the left with nothing. IMHO this could be done way easier (just replace the characters from the left), but I think @BenoitAverty just took this pattern from the truncate_with_package_name strategy. As far as I can see this pattern originates from barts prompt. For more information about this pattern, see this answer on StackOverflow.

Regarding the performance of upsearch function. For me it looks quite solid. Nothing to optimize here.

@bhilburn
Copy link
Member

This is really well done, @dritter. I especially like your approach to creating user documentation, which I think makes things easier to use.

@BenoitAverty - This is a great idea, and I appreciate you providing input & review on this PR. Thanks for coming up with so many great improvements for the project!

Now the current folder in `truncate_with_folder_marker` strategy is
truncated by cutting off the found folder from the beginning of $PWD.
@dritter
Copy link
Member Author

dritter commented Feb 12, 2017

I just got rid of the ugly pattern. Now the current path is truncated by removing the matched path from upsearch from $PWD. This is much more readable in my opinion.

@BenoitAverty could you confirm that everything still works as expected? I mean, I have tested it as well, the tests are green, but the more eyes, the better. 😉 Thanks in advance.

@dritter
Copy link
Member Author

dritter commented Feb 12, 2017

Btw. There is still this ugly pattern in truncate_with_package_name, I will fix this in a different PR.

@BenoitAverty
Copy link
Contributor

I did a quick test just now, it seems to work OK. I may have forgotten some edge cases, but it works with one and two markers in the hierarchy so it should work in all cases.

@dritter
Copy link
Member Author

dritter commented Feb 13, 2017

Good to hear! Thanks for testing @BenoitAverty

@bhilburn bhilburn merged commit 2210300 into Powerlevel9k:next Feb 14, 2017
@bhilburn
Copy link
Member

Awesome :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants