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

Experiment: ZSH only version of async files changes #83

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

Conversation

michaeldfallen
Copy link
Owner

This pull request is an experiment. If you use ZSH please pull it and try it out as I'm looking for feedback.

In this pull request I have taken the longest part of the radar, the file changes (0.245s out of 0.25s on my machine), and made it async. It now cat's a file in .git and spawns an async subshell to populate that file. Then using ZSH's zle reset-prompt we are able to cause the shell to re-render once the async subshell has completed.

async-radar

It's flaky and hacky and only a first pass but it does mean the initial prompt render is almost instantaneous. The file changes then asynchronously populate later.

To use:

You need to add a definition for the zsh function TRAPUSR1 to your .zshrc:

function TRAPUSR1() {
  # redisplay the prompt
  zle && zle reset-prompt
}

@michaeldfallen michaeldfallen changed the title ZSH only version of async files changes Experiment: ZSH only version of async files changes Oct 21, 2015
@mengelbrecht
Copy link

Will this feature be optional? I am already calling git-radar asynchronously in my zsh theme slimline and rely on git-radar being synchronous.

@michaeldfallen
Copy link
Owner Author

@mgee it was your link to slimline that inspired me to attempt this. I would intend to make this a feature flag that can be turned on or off.

Async bash would end up redisplaying only after a second prompt render, which could be annoying, and zsh async would require you to do further work to use it, which some might miss. So I wouldn't want to make this the default either.

@michaeldfallen
Copy link
Owner Author

Ok, I've cleaned this up and applied it to the rest of the prompt. Now every part is constructed asynchronously and the prompt is refreshed multiple times. There's still work to do to make the interface for the refresh work properly so I haven't added that in just yet.

If you want to test this out add the following to your ~/.zshrc:

function TRAPUSR1() {
  RPROMPT="$(date)"

  # redisplay
  export GIT_RADAR_REDRAW=true
  zle && zle reset-prompt
  export GIT_RADAR_REDRAW=false
}

export GIT_RADAR_ZSH_PID="$(echo $$)"
export GIT_RADAR_ASYNC_EXEC=true

That will cause the prompt to be rerendered when a USR1 signal is fired, which is fired after each async part completes. The current date and time will be set in your RPROMPT as well so you can see when the trigger fires. Get rid of that part if it's not for you.

I plan to make that interface as easy as eval "$(git-radar --zsh-traps)" or something so it isn't hard for people to use.

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

Successfully merging this pull request may close these issues.

None yet

2 participants