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

use gitstatus #336

Open
Konfekt opened this issue Apr 7, 2019 · 12 comments
Open

use gitstatus #336

Konfekt opened this issue Apr 7, 2019 · 12 comments

Comments

@Konfekt
Copy link
Contributor

Konfekt commented Apr 7, 2019

Since this is supposed to be a fast framework for zsh, including the git status prompt, using gitstatus by https://github.com/romkatv/gitstatus instead of git status to speed up the prompt git status display seems pertinent.

@PatTheMav
Copy link

I like the idea in general, but it's obviously depending on a platform-specific binary being present on the system and the zsh plugin creating a pipe to this binary running as a background daemon.

I believe that these requirements run counter to the idea of just downloading/sourcing a single .zsh file and thus running Zimfw.

However I could see this as either:

  • An optional module that can be activated by users with required documentation as how to source/install gitstatusd.
  • The current gitstatus module detecting the availability of gitstatusd and using it, with the current implementation as a fallback.

The second variant might require the gitstatus module to implement the pipe to gitstatusd while keeping the internal API as-is.

@thepigeonoftime
Copy link

@Konfekt until there is a decision for this, https://github.com/romkatv/powerlevel10k comes packaged with gitstatusd, the install instructions here https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions#option-9-install-for-zim should work when edited correspondingly, if it does you just have to disable zims git plugins and maybe rebuild cache. Working well for me.

@thepigeonoftime
Copy link

@PatTheMav I would probably vote for an optional, documented module- using a fallback might introduce confusion about different speeds between users / systems / setups.
The maintainer of gitstatusd ( @romkatv ) seems very responsive and helpful (e.g. romkatv/gitstatus#7 ), asking him for some input could be worth it.

@romkatv
Copy link

romkatv commented Apr 13, 2019

Thanks for looping me in.

gitstatus has zsh bindings that just work. It can be installed and used like a regular zsh plugin. The fact that heavy lifting is done by a native binary is an implementation detail.

git clone https://github.com/romkatv/gitstatus.git ~/gitstatus
source ~/gitstatus/gitstatus.plugin.zsh

(It also works with all popular plugin managers.)

If you want to use gitstatus in your code only if the user has installed it, you can do the following.

  • To check whether gitstatus has been sourced, look for function gitstatus_start.
  • If this function is defined, you can start gitstatusd (the daemon) with gitstatus_start MY where MY is a unique ID of the theme/plugin that wants to use gitstatusd. You need to call gitstatus_start MY at least once in every interactive shell where you intend to query gitstatus. If the daemon is already running, the call will have no effect.
  • Before querying gitstatus, you can call gitstatus_check MY to check whether gitstatusd is running. This isn't required though; gitstatus_query will perform the same check anyway.
  • Call gitstatus_query MY to get status of the current git repo. If successful, it'll set a bunch of global parameters whose names start with VCS_STATUS.

Here's an example:

gitstatus_start MY
gitstatus_query MY
set | egrep '^VCS_STATUS'

When I run it while in /home/romka/.oh-my-zsh/custom/plugins/powerlevel10k, I get the following output:

VCS_STATUS_ACTION=''
VCS_STATUS_ALL=( /home/romka/.oh-my-zsh/custom/themes/powerlevel10k 1d7c63f80fcc1ea1b79342c972fe77e3e2ec80e4 master master origin git@github.com:romkatv/powerlevel10k.git '' 0 0 0 0 0 0 '' )
VCS_STATUS_COMMIT=1d7c63f80fcc1ea1b79342c972fe77e3e2ec80e4
VCS_STATUS_COMMITS_AHEAD=0
VCS_STATUS_COMMITS_BEHIND=0
VCS_STATUS_HAS_STAGED=0
VCS_STATUS_HAS_UNSTAGED=0
VCS_STATUS_HAS_UNTRACKED=0
VCS_STATUS_LOCAL_BRANCH=master
VCS_STATUS_REMOTE_BRANCH=master
VCS_STATUS_REMOTE_NAME=origin
VCS_STATUS_REMOTE_URL=git@github.com:romkatv/powerlevel10k.git
VCS_STATUS_RESULT=ok-sync
VCS_STATUS_STASHES=0
VCS_STATUS_TAG=''
VCS_STATUS_WORKDIR=/home/romka/.oh-my-zsh/custom/themes/powerlevel10k

You can also call gitstatus_query asynchronously by passing it a function that will be called after all VCS_STATUS parameters are set.

See high level docs at https://github.com/romkatv/gitstatus and details at https://github.com/romkatv/gitstatus/blob/master/gitstatus.plugin.zsh. You can also read the code of Powerlevel10k to see how it integrates with gitstatus, although it's kinda brutal. Ping me if you have any questions.

@lnicola
Copy link
Contributor

lnicola commented Apr 13, 2019

@romkatv I think one of the issues is that gitstatus has a different interface from the popular git-info ZSH plugin. So existing themes can't integrate with it directly.

@romkatv
Copy link

romkatv commented Apr 13, 2019

@lnicola Could you give me a link to the popular git-info ZSH plugin? Google gives me nothing when I search for "git-info" ZSH plugin.

@lnicola
Copy link
Contributor

lnicola commented Apr 13, 2019

Sorry, I thought it was a widely-used plugin. Apparently, zim has its own version of it (but with what seems to be a similar interface).

@PatTheMav
Copy link

@romkatv In essence, git-info stores its data in zstyle fields (populated from a precmd), and establishes a set of macros that can then be used in "styling" git information for prompt and/or rprompt.

While gitstatus can be patched into a zim setup by users themselves, a proper plugin IMO needs to be a drop-in replacement for git-info so that themes can make use of its improvements out of the box.

@romkatv
Copy link

romkatv commented Apr 13, 2019

@lnicola Thanks for the links.

I believe the only ZSH API for querying git status that deserves adjective "popular" is vcs_info. Everything else, including my gitstatus, is marginal.

Integrating gitstatusd right into vcs_info could be a worthwhile project. I haven't attempted it yet because I expect this to be a costly endeavor. Not for technical but rather organizational reasons.

Writing a wrapper over gitstatus to emulate another API isn't too difficult. I've done exactly this in Powerlevel10k. This theme can generate the same prompt by using either gitstatus or vcs_info. The API here is made of configuration options supported by the theme, and there are two implementations of it. It did help that I could easily add extra features to the daemon whenever I needed them, which may not be something you can do. But if you open an issue explaining what's missing for your use case, or send a PR, we can get it done.

@romkatv
Copy link

romkatv commented Apr 13, 2019

While gitstatus can be patched into a zim setup by users themselves, a proper plugin IMO needs to be a drop-in replacement for git-info so that themes can make use of its improvements out of the box.

Sounds cool. Just to be clear, I'm not volunteering to do this. If anyone else wants to give it a shot, I can promise to provide high-quality support from gitstatus side of things.

@PatTheMav
Copy link

@romkatv Sure, no worries. Also none of us are the authority on this, that'd be @ericbn or @Eriner 😁 (Even though anybody can write a zimfw plugin and add the Github repos to their own zimrc with the version on the develop branch).

I don't think it's impossible to write such a plugin (which would populate zstyle fields instead of the ENV), it might require some proper init routines from your own zsh API, but I haven't checked it out in depth. Alas I'm swamped with other projects right now, otherwise I'd given it a try already.

@ericbn
Copy link
Member

ericbn commented Apr 15, 2019

I like @p1g30n's idea o having a separate gitstatus-git-info module instead of updating the current git-info to use gitstatus as a fallback. Just not sure if we should have gitstatus as a submodule of gitstatus-git-info. This would definitely not make sense in the bleeding-edge develop branch of Zim.

I started to work on this, and PRs are welcome too.

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

No branches or pull requests

6 participants