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

Add support for modifying the pre-prompt (add / edit / remove pre-prompt parts) #460

Open
mafredri opened this issue Feb 4, 2019 · 10 comments
Labels
💵 Funded on Issuehunt This issue has been funded on Issuehunt enhancement

Comments

@mafredri
Copy link
Collaborator

mafredri commented Feb 4, 2019

Issuehunt badges

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 #458 (comment)

There is a $80.00 open bounty on this issue. Add more on Issuehunt.

@CircleCode
Copy link

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 :-)

@warbaque
Copy link

warbaque commented Feb 11, 2019

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.

@onyxraven
Copy link

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.)

@awmottaz
Copy link

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-oss issuehunt-oss bot added the 💵 Funded on Issuehunt This issue has been funded on Issuehunt label May 2, 2019
@IssueHuntBot
Copy link

@IssueHunt has funded $80.00 to this issue.


@sindresorhus
Copy link
Owner

sindresorhus commented Jun 17, 2019

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.

@awmottaz
Copy link

@sindresorhus take a look at nvm

@sindresorhus
Copy link
Owner

@awmottaz Yes, I'm aware of nvm and the other version managers.

@ashb
Copy link
Contributor

ashb commented Jun 21, 2019

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?

@sindresorhus
Copy link
Owner

We could look at https://github.com/denysdovhan/spaceship-prompt for inspiration about customizability (They already got a lot of inspiration from Pure).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💵 Funded on Issuehunt This issue has been funded on Issuehunt enhancement
Projects
None yet
Development

No branches or pull requests

8 participants