Bash-it / bash-it

A community Bash framework.
MIT License
14.29k stars 2.29k forks source link

How to optionally configure custom prompts? #801

Closed manojlds closed 3 years ago

manojlds commented 8 years ago

I see that prompts are mixed with themes. How do I add a new prompt that is optional. Like how plugins can be enabled? Am I missing something?

nwinkler commented 8 years ago

Not sure I understand what you're looking for...

Themes really are prompts - if you want a custom prompt, just copy one of the existing ones and make the changes you want.

manojlds commented 8 years ago

@nwinkler - I understand that from personal use point of view. What if I wanted to contribute it here?

Actual use case - I am trying to add Kubernetes kubectl context to my prompt. I would also like to contribute that back to bash-it. But not everyone would want it to be enabled right? How can I let people who want it, to enable it?

nwinkler commented 8 years ago

Got it, thanks, that makes sense.

We don't have a standard approach for that, but here are a couple of ideas:

Once you've made the changes that implement this new feature, feel free to create a Pull Request and we'll review that together.

giggio commented 4 years ago

One way to see the Kubernetes prompt is to use https://github.com/jlesquembre/kubeprompt/ with Bashit. But I could not get it to work.

davidpfarrell commented 4 years ago

Greetings All !

Regarding Optionally Configuring

As @nwinkler mentioned, the Powerline themes are an excellent example of a theme that lets you optionally include different pieces of information into your prompt.

In Powerline, each different piece of information is called a segment.

Each segment has a code name and you use the code names to chose which segments you want, AND in which order they should be displayed.

Example with scm context

export POWERLINE_PROMPT="user_info scm cwd"
user_scm_cwd

Example without scm context and different segment order

export POWERLINE_PROMPT="cwd user_info"
cwd_user
Regarding K8s Context:

Have a look at recently-added PR #1476 and the discussion I started there.

It introduces logic to for the k8s_context with my recommendation being to centralize that logic so all themes can take advantage of it.

I imagine that the k8s segment would be incorporated into bash-it similar to how the scm segment is incorporated, so you might want to look at that for inspiration.

@manojlds, you and @Diogo-Costa might be able to collaborate on this effort.

-D

ttmms commented 4 years ago

@davidpfarrell Thanks for this input. I'm still stuck with this, though. I want to add a simple segment to my powerline. If $MY_ENV_VAR exists, print its value, with the colors I want. I have been trying to find for example where "user_info" segment is defined so I could copy it, but I just cannot find any references to it, or any of the segment names. Where are they defined? Thanks!

In bobby theme it was easy, I just added my variable in the PS1 string with the ${color} I want, but I cannot get it to work with powerline, so it would actually look like powerline and not just text

nwinkler commented 4 years ago

Hey @tuomassa - thanks for the question.

The user_info segment function is defined here:

https://github.com/Bash-it/bash-it/blob/9e92ef342f9673559e78220b14cd535aa631f4c7/themes/powerline/powerline.base.bash#L16

The naming convention for the Powerline segments is __powerline_segment_prompt, all of the functions can be found in the powerline.base.bash file. So for the node segment, the function is called __powerline_node_prompt, for example.

Does that help?

ttmms commented 4 years ago

@nwinkler Yes, thanks alot! I was actually trying to modify powerline-multiline and didn't notice it actually sources the normal powerline theme so I was not looking in the right place!

nwinkler commented 4 years ago

You're welcome!