-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Git-plugin: Don't truncate commit number #41
Conversation
A branch name shouldn't be a commit number, and a commit number should always be in the long format. Themes can reduce the size of the commit id, and they should be able to choose between the branch name or the commit id
On commit length, I wanted to make theming easier because many themes in OMZ Robby have issues. When are you ever going to be able to fit the full commit in a prompt? I think you're right on branch should never be a commit when the branch is missing. However, I do not like |
At one time, I had a commit style where you could specify if %c meant long or short, and short was always 7, which is standard, but I removed it since realistically I do not see anybody fitting the full commit in a prompt. |
Regarding the commit length, it's clearly a formatting issue, and therefore should be handled during the formatting part (even if it's said that by default only 7 chars are selected, anyone should be able to have the full commit name (if you have a multi lines prompt that could be feasible to use the full name). Regarding the branch_is_set and the ternary operator, I haven't figured out how to format with conditions, this was the best way I could come with. If there is something better I would be glad to see that :) |
Well, I used %C for clean but %C could mean full commit id, and we can find synonyms for clean/dirty. I used %C and %D for clean and dirty to avoid the ternary operator. :( |
I don't really like the ternary operator as it doesn't handle strings and in the end it's just a "hack", but multiplying variables for every possible case isn't a nice solution either. In my current theme I have this system to print the current position:
But handling this with new variables for each case starts to be a nightmare. The same thing applies with other "conditions". For example, when my current branch has a remote, and that remote in neither behind or ahead I want to print "=". Doing that condition without ternary is just awful. Plus, I think that the theme should do all the formatting, it shouldn't be handled at all by the plugin. The 'rule' of one variable, one value helps to keep the code clean. I would really like to see a better solution, but unless zsh formatting system has other options this is somehow the best solution I can think of. |
|
I would rather use the current system even if there is more variables for the size of some strings. It's clearer and easier to format. Being stuck with ternary operator instead of having a huge script in the theme file is, I think, a good trade-off |
Yeah, but what letter do you use for the size of strings? An easy pattern would be for |
Maybe, we can fake our own ternary. It's ugly and slower, but it's better than polluting the code with a tonne of length variables. function fake-ternary() {
if [[ -n "$argv[1]" ]]; then
print "$argv[1]"
return 0
elif [[ -n "$argv[2]" ]]; then
print "$argv[2]"
return 0
else
return 1
fi
}
zstyle ':omz:plugin:git:prompt' prompt ' %F{blue}git%f$(fake-ternary "%b" "%c")%s' |
That's not really a ternary since we are not passing it a condition, more like |
By the way, Zsh has a math ternary |
Yes, it was more an elvis operator than a ternary.
It seems that you can't just run code when formatting. Regarding the letter I just chose a random one, but it would have been indeed way easier to have uppercase = size of string. |
It also seems that the math ternary is only "math" (surprise), it's not possible to do |
I wasn't thinking of running code when formatting with what you call the elvis operator ( |
It's maybe more work, but rearranging the letters to have the uppercase/lowercase system seems to be the best solution (It's more clean) |
I'm going to try to see if I can get a function to work. function not-empty() {
for arg in $argv; do
print "$arg"
return 0
done
return 1
}
not-empty "" "" "" "mybranch" "89f321d" It will print the first non-empty argument. |
I was thinking about a Coalesce too, but I'm still not convinced that having to write script is the best solution |
No, that function would go into helper.zsh. |
Yes, but if you want to create your prompt, you will have to write a script (using this function) which is slower than a simple format. |
You mean you'll have to execute a sub shell. It's not that slow. You're executing a function in a sub shell, not an external script. |
Tried zstyle ':omz:plugin:git:prompt' prompt ' %F{blue}git%f:$(not-empty "%b" "%c")%s' Got
I need to figure out how to make Zsh execute it. I've been playing with quotes with no success. |
I'm not sure it worth doing that much work. Here are the values right now:
With my patches I add a new value, So it's 6 new characters. It isn't that much and if one day the ternary operator is fixed to allow strings (using the length as a mathematical expression) we will be able to remove most of these chars. I have nothing against the ternary operator, it's the idea of using new chars for length that bothers me, but if we don't need that many new variables, I think it's better to create these. |
While the counts may be integers, the formats are all strings, not integers nor booleans. I do not want to remove Making that function execute, if possible, is simpler than changing all those formats and frees letters for more formats. |
Indeed, I forgot that it was the formated value, not the count itself. Regarding |
Yes, but if you have formatted dirty, the ternary will fail. |
If it hasn't changed you get ø, otherwise you get ð |
I value consistency over ternary tricks, but yes, that can be used. I'll consider it. |
I didn't mean to close the issue. It seems that pushing to a branch other master closes GitHub issues as well. I have a solution to this. It's not pretty, but it's better than plastering |
I saw that on #zsh. As you said, it's not pretty, but it could be useful later if someone wants to add more "custom code". It works also with my |
I have looked at |
Can you think of a better name than |
As it mostly acts like a I'm fine with that commit. And for what it worths, I've read the documentation on zstyle countless time I never actually noticed that |
Yes, you have mentioned that before, but I have looked at Apple's dictionary, which defines the word as 'come together to form one mass or whole', which makes it seem more like a synonym for catenation. |
I just tried to get in headless, here is what I got:
The spacing issue has been fixed, but I don't get a commit id. |
After investigation, (I changed temporarily the result of coalesce in |
I see |
There is another problem. The branch will never be empty due to formatting. Coalesce might need a regex. |
Maybe |
Try 5e5a780. |
Yes, this patch works for me, and it's even better as you dont have to set the reply. |
I had my sight on something like this before Mikachu distracted me with Now, I can style the commit in a different colour from the branch; before, it was not possible. Though, I do not believe there was much confusion. Who would name a branch with alphanumeric gibberish? However, all colours seem to be taken. I should probably convert it to 256 colours, but right now I am lacking inspiration. |
Update README.mkd
sorin-ionescuGH-19: Respect the HIST_FIND_NO_DUPS option.
* 'master' of https://github.com/zsh-users/prezto: (53 commits) Allow setting ZPREZTODIR to make prezto easier to integrate with (sorin-ionescu#54) documenting PR approval process defined in sorin-ionescu#41 (sorin-ionescu#45) Revert "Restore the parser status to PS2" Fix typos and link usernames Clearly define who are the project leaders (sorin-ionescu#26) Restore the parser status to PS2 Revert "resolve race condition between git completion and coalesce function" Fix links in README Do not call `editor-info` in `zle-line-finish` Bump license years and tidy up readme Provide upgrade instructions + link to new fork ssh: update ps|grep ssh-agent check Don't load pfunctions from vi swap files Add module 'encode64' from oh-my-zsh (renamed to 'base64') Add module 'fancy-ctrl-z' from oh-my-zsh Update all submodules Discover and reuse existing ssh-agent if possible added maven plugin from oh-my-zsh Add basic set of aliases for npm Revert "use non breaking space" see sorin-ionescu#14 ...
A branch name shouldn't be a commit number, and a commit number should always be in the long format.
Themes can reduce the size of the commit id, and they should be able to choose between the branch name or the commit id.