pure
pure copied to clipboard
Add support for modifying the pre-prompt (add / edit / remove pre-prompt parts)
This issue is for tracking discussion and development of an extension to the pre-prompt that will allow users to make modifications to it by some means.
The purpose is to minimize the need for our users to maintain a fork just so that they can add some information to the pre-prompt.
Prologue: It would be nice to provide an API that allows user defined segments to run asynchronously as well. And it should be simple enough that it’s hard to make mistakes. Ordering of parts/segments would also be nice and if we ever make a new segment it would be nice if the user doesn’t have to manually enable it due to hard coding the current segments, or whatnot.
Perhaps functions like prompt_pure_add_segment myfunc
and _set_order myfunc 3
(moves it to pos 3 and old 3-n are offset by one).
Another thought I’ve had is more hook-like, e.g. right before re-rendering the prompt. A hook function is called where you can manually modify the preprompt array, but it requires a bit more intimate knowledge of how to work with zsh arrays.
Issue originally raised by @sindresorhus in https://github.com/sindresorhus/pure/pull/458#issuecomment-459633908
There is a $80.00 open bounty on this issue. Add more on Issuehunt.
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on Issuehunt to raise funds.
do you expect users to list segments they would love to see available (so that you can pre-code them, even if they are not enabled by default)? On my side, I'd love to see
- numbre of stash
- upstream name
In case you are not expecting input like this, feel free to delete my comment :-)
for workaround I added
preprompt_parts+=($(custom_prompt_parts 2>/dev/null))
to prompt_pure_preprompt_render()
with no other customization options (I just needed way to add extra parts to the end)
Then just have custom_prompt_parts()
in my settings env
But something similar would be nice.
Just throwing in my support - I've been using the https://github.com/intelfx/pure branch (which is now really far behind), but allows customization by adding to prompt_pure_pieces
(https://github.com/intelfx/pure#example-1)
(I've added things such as a shrunken path via oh-my-zsh shrink_path
, kubernetes context via kctx
, aws-vault profile, etc.)
I would also like to see this feature added. I enjoy using t
to manage quick todo tasks, and I would like to add the number of incomplete tasks to my prompt.
@issuehunt has funded $80.00 to this issue.
- Submit pull request via IssueHunt to receive this reward.
- Want to contribute? Chip in to this issue via IssueHunt.
- Checkout the IssueHunt Issue Explorer to see more funded issues.
- Need help from developers? Add your repository on IssueHunt to raise funds.
One use-case I had in mind for this:
I've been wanting a way to automatically switch the active Node.js version when I enter a Node.js project. It would switch to match the Node.js range in the "engines"
field in package.json. That way I can ensure I don't use JS/Node.js features that should not be used.
I would use n
for the actual switching. I don't like nvm
. It's too buggy.
@sindresorhus take a look at nvm
@awmottaz Yes, I'm aware of nvm
and the other version managers.
I can see a copule of ways of approaching this customization.
Step 0. split the rendering of part prompts in to functions;
Then:
Option a: something like intelfx branch.
# optionally define custom generators
prompt_custom() {
preprompt_parts+=( custom )
}
prompt pure
# add the generator where it's needed
prompt_pure_pieces=(
${prompt_pure_pieces:0:2}
prompt_custom
${prompt_pure_pieces:2}
)
Thought the API suggested by the OP is probably nicer
Perhaps functions like
prompt_pure_add_segment myfunc
and_set_order myfunc 3
(moves it to pos 3 and old 3-n are offset by one).
This allows "full" control but would be fragile to ordering change of the built in prompt parts.
Option b: add pre
and post
hooks to the functions from step 0. meaning something like this would add sparkles to the start of every line
custom_start() {
preprompt_parts+=(✨)
}
pure_add_hook pre path "custom_start" # ZSH is new to me - can we pass functions by anything other than name?
Option c: combine both of them for total control.
Does anyone have thoughts?
We could look at https://github.com/denysdovhan/spaceship-prompt for inspiration about customizability (They already got a lot of inspiration from Pure).