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

Add support for more contexts #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

couloum
Copy link

@couloum couloum commented Sep 20, 2024

I suggest this PR to add support for the following new contexts:

  • added files (%a)
  • modified files (%m)
  • deleted files (%d)
  • renamed files (%r)

These contexts are only available when verbose is set to yes.

I used the same code letters than original prezto/git module for a better compatibility.

With this PR, we can have more information on the 'dirty' state as we now see the different reasons of why a repo is dirty.

Example of prompt:

#  zstyle ':zim:git-info' verbose 'yes'
#  zstyle ':zim:git-info:branch' format "%F{white}%b%f"
#  zstyle ':zim:git-info:clean' format "%F{green}✔%f"
#  zstyle ':zim:git-info:dirty' format "%F{red}≠%D%f|"
#  zstyle ':zim:git-info:added' format "%F{white}✚%a%f"
#  zstyle ':zim:git-info:deleted' format "%F{white}✖%d%f"
#  zstyle ':zim:git-info:modified' format "%F{white}●%m%f"
#  zstyle ':zim:git-info:untracked' format "%F{white}?%u%f"
#  zstyle ':zim:git-info:renamed' format "%F{white}r%r%f"
# zstyle ':zim:git-info:keys' format \
#   'status' '(%b|%C%D%a%m%d%r%u)'
(main|≠5|✚1●1✖1r1?1)

@ericbn
Copy link
Member

ericbn commented Sep 20, 2024

Hi @couloum. I know these context exist in prezto's git-info, but I think it's too much information and I prefer to keep it simple, like we try to keep it simple in zimfw.

(I was considering adding an unmerged context, so files with merge conflict show up in this context instead of both indexed and unindexed, but I'm still thinking it twice and didn't implement it yet.)

Any new context need to be used in at least a couple of our themes for it to make sense. Of course all these context proposed here could be added to the sorin theme. But I specially like how our fork of sorin is less poluted with symbols than the original prezto version.

EDIT: Also, these new context require the verbose mode, which makes the prompt slower when enabled, so we try to avoid it. In fact, only our forks of the steeef and sorin themes use it.

@couloum
Copy link
Author

couloum commented Sep 20, 2024

Thank you for your prompt answer. I understand the philosophy to have minimal and non-bloated framework. I currently use prezto and consider using zimfw especially for that. I do have created my own prompt in prezto that do contains these contexts. Therefore I added them for myself and suggested a PR to have this integrated mainstream. But I can leave with my own fork.
It just felt to me that it was not a big addition considering that there's no additional command executed by the module. I didn't do benchmarks, but I would say that performance impact is negligible. And nobody is forced to use these. It's just a feature available for anyone wanting to use that their custom themes.

I let you decide whether or not you should validate this PR.

@ericbn
Copy link
Member

ericbn commented Sep 20, 2024

I'll leave this open to see if there's any interest in it.

You can always use prezto's git-info instead of ours with:

.zimrc

zmodule sorin-ionescu/prezto --root modules/git
zmodule git

.zshrc (on top)

zstyle ':prezto:module:git:alias' skip 'yes'

Comment on lines +133 to +138
if [[ ${line:0:1} == 'A' ]] ((added++))
if [[ ${line:0:1} == 'M' ]] ((modified++))
if [[ ${line:1:1} == 'M' ]] ((modified++))
if [[ ${line:0:1} == 'D' ]] ((deleted++))
if [[ ${line:1:1} == 'D' ]] ((deleted++))
if [[ ${line:0:1} == 'R' ]] ((renamed++))
Copy link
Member

Choose a reason for hiding this comment

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

Note that this might be tricker that what's implemented here. Sorin came up with this at the time:

https://github.com/sorin-ionescu/prezto/blob/9195b66161b196238cbd52a8a4abd027bdaf5f73/modules/git/functions/git-info#L367-L375

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

Successfully merging this pull request may close these issues.

2 participants