apollo-zsh-theme
apollo-zsh-theme copied to clipboard
git module in scrollback theme
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?
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.
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?
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:
- Rename the
__apollo_git_always_async
function to__apollo_sync_git_run
. - 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. - 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:
- Remove the
__apollo_sync_git_cache_key
function and accept the performance hit. - Edit the function to choose a more appropriate cache key if you can think of one.
- 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.