WIP: Git super status as template string#40
Open
NAR8789 wants to merge 36 commits intostarcraftman:masterfrom
Open
WIP: Git super status as template string#40NAR8789 wants to merge 36 commits intostarcraftman:masterfrom
NAR8789 wants to merge 36 commits intostarcraftman:masterfrom
Conversation
304a99c to
2c031fa
Compare
POSIX_ARGZERO not supported in zsh 5.0.2
2c031fa to
151c01a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NOTE: this builds on top of some unit testing brought in in #39, and that PR is generally less weird than this one, so you should probably read #39 first.
This PR is an attempt (possibly misguided) at allowing "template-string"-like customization of the git prompt.
For example, here is the original theme in template-string form:
Here is an example retheming involving custom template string (template string is the last line)
And here are some example prompts under that custom template
Why?
I think template strings potentially provide an easier way to make structural modifications to the git-prompt theme, e.g. omitting or reordering pieces. Reordering by moving variables around in a template string feels a lot lighter weight than overriding
git_super_statusand reordering the blocks therein.At the end of the day it's about having varying levels of granularity in configuration. The preexisting theme variables already nicely support fine-grained changes (i.e. tweaking look-and-feel in-place), so I've written this template string implementation to avoid that level of granular detail, and to leave that existing layer of customizability intact.
Template strings fill in a missing level of granularity--providing the ability to work at the level of prebuilt status blocks, e.g.
✖4, or●3. orREBASE 2/7In theory this might also be a nicer place to configure separators and margins, rather than using
ZSH_THEME_GIT_PROMPT_PREFIX,ZSH_THEME_GIT_PROMPT_SUFFIX, andZSH_THEME_GIT_PROMPT_SEPARATORWhy Not?
Template strings sound nice, but in practice I find them headachey in particular for optional separators or spacers (e.g. "omit this spacer if the next section is empty"). Optional Spacers require a tiny bit of logic, and I found zsh expansions an awkward tool for this purpose.
For example, my custom template above contains optional separators logic, but it reads like a code golf solution.
Here is my example custom template string again:
At a high level, the idea I'm implementing above is simple:
$branch,$upstream,$merge_or_rebase, and$behind$ahead$staged$conflicts$changed$untracked$stashed$clean|as separatorsZsh has built-in support for joining arrays:
${(j:|:)array_var}will join the elements of$array_varwith pipes|. You can see this at the outermost layer of my expression, just inside the literally-printed parens.The rest of the expression,
${(s:|:)${:-...}}, is a hack to declare an anonymous array inside of a string.${(s:|:)string_var}splits a string on pipes${:-string_expression}is a hack, to shoehorn an arbitrary string expression into the above splitter. Otherwise, thestring_varargument above would only take variables, not arbitrary expressions. credit to stackoverflow for this one.Note that, though this works for the current purpose, this is not fully general:
Given the weirdness of zsh expansions, it feels like template strings might be hard for most people to write from scratch.
Extra Bits
As part of this, I wrote a previewer tool, to see the git status under various conditions all at once, without needing repositories to produce the correct underlying states. It's invoked as
preview_git_super_status, and lives in a separate file so as not to clutter the main logic. It avoids polluting the environment by doing all its work in a subshell.