Pergunta

I have an usual displaying of info from GIT like current branch name, and is repo is in "dirty" state within prompt. The problem is that some larger repos take a good few seconds to calculate the "dirty" state.

Is there a way to issue the dirty check asynchronously, to not hold down the responsiveness of shell? PS I'am using fish 2.0 shell.

Foi útil?

Solução

If you use git diff-index --quiet HEAD --, it will stop processing at the first diff encountered instead of processing the entire source tree, so that may help you with execution time.

In addition, you can use a temporary buffer for your current dirty state, such as a file in /tmp. Then, your prompt command will take the content of that file and use it in the prompt, after which it will launch a background update to the repo (such as git diff-index --quiet HEAD -- && echo clean >/tmp/myreponame.status || echo dirty >/tmp/myreponame.status &).

One thing you should be careful with is that the background update will be launched for every prompt, meaning you may end up with several of those running at the same time. To avoid that, you'll need a script that checks if it's already running and either quits or kills the older instance.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top