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

git module in scrollback theme #5

Open
CircleCode opened this issue May 4, 2020 · 3 comments
Open

git module in scrollback theme #5

CircleCode opened this issue May 4, 2020 · 3 comments

Comments

@CircleCode
Copy link

It seems the git module provides no output at all in scrollback theme.

As noted in https://github.com/mjrafferty/apollo-zsh-theme/blob/master/docs/theme_guide.md#scrollback-theme

Note that asynchronous modules will NOT run for a scrollback theme.

Although I expected it to reuse previously computed values. Is it possible?

@mjrafferty
Copy link
Owner

The scrollback theme does not use previously computed values because its configuration can be completely unique from the main theme. The cached value for the git output would be generated based on the main theme's configuration, so it would not work well if someone wished to have it display differently from the main theme's configuration. The cache key for each module also contains the theme name and information about where that module is located on the prompt, which wouldn't match up with the scrollback theme.

What I could do for this is to implement an additional more generic caching method for scrollback themes to pull from on async modules. It would require each async module to have additional code to populate that cache and possibly an additional function to parse it if needed. This would be the best way to keep added overhead down while still providing the same flexibility and configuration options to scrollback themes.

For now I have no immediate plans to implement that, but if this issue gets more attention from others I can make it a priority. I could also just decide to do it one day if I don't have a lot going on, but I've been pretty busy lately so that might not happen anytime soon.

@CircleCode
Copy link
Author

Thanks for this detailed explanation.
I get the path you took, and I understand the amount of work that would be required.

Maybe you can add into the readme for each module if it can be used in scrollback theme as an indication (and point to this issue) for explanation?

Side question: If I want only local-branch and commit-hash in scrollback theme, do you see a way to achieve this, like a synchronous git-lite module?

@mjrafferty
Copy link
Owner

The simplest way to get that would be to copy the existing git module:

https://github.com/mjrafferty/apollo-zsh-theme/blob/master/modules/__apollo_git_load

Say we call the new module sync_git, you can copy the above file into a file called $HOME/.local/share/apollo/__apollo_sync_git_load or $XDG_DATA_HOME/apollo/__apollo_sync_git_load.

You'd then need to make the following changes:

  1. Rename the __apollo_git_always_async function to __apollo_sync_git_run.
  2. Move __apollo_git_getaction and __apollo_git_getbranch from inside the __apollo_git_init_async function to outside of it as the __apollo_git_init_async won't be used.
  3. Rename all function prefixes in the file from __apollo_git_ to __apollo_sync_git_.

This should give you most of the same functionality as the normal module, and as long as you're only using the commit hash and local branch it shouldn't be too bad on performance. The downside here will be with stale cache on commit or branch change. The cache key uses the current working directory and won't update as long as cache exists. You have a few options for this:

  1. Remove the __apollo_sync_git_cache_key function and accept the performance hit.
  2. Edit the function to choose a more appropriate cache key if you can think of one.
  3. Deal with stale cache. You can manually flush cache for all modules by pressing enter a few times by default which will cause the prompt to update.

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

No branches or pull requests

2 participants