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

Pre/Post prompt customization #34

Closed
mattmc3 opened this issue Jun 17, 2022 · 13 comments · May be fixed by #37
Closed

Pre/Post prompt customization #34

mattmc3 opened this issue Jun 17, 2022 · 13 comments · May be fixed by #37
Labels
enhancement New feature or request

Comments

@mattmc3
Copy link
Collaborator

mattmc3 commented Jun 17, 2022

@jorgebucaran - Are you open to a PR that would introduce two new variables into the prompt: a pre-prompt and a post-prompt like so...

set --query hydro_pre_prompt || set --global hydro_pre_prompt ""
set --query hydro_post_prompt || set --global hydro_post_prompt " "

The intent of the hydro_pre/post_prompt variables would be to allow users some to way to customize their prompt without having Hydro have to directly support all the customizations a user might dream up. For example, I like a more spacious prompt similar to Zsh's Pure, so I could get that by setting the pre-prompt variable to a new line in my config like so: set --global hydro_pre_prompt "\n".

Theoretically, with these variables a user could do whatever they wanted like adding a low battery indicator 🔋, or a python symbol 🐍 when they're in a python venv, or whatever - all without having to modify hydro itself. I'm open to other ideas on an implementation - just thought this would be a real simple change that would give the user more power in customizing their Hydro prompt.

The only change to Hydro in the PR to implement this would be adding those variables and then changing the fish_prompt function:

function fish_prompt
    echo -e "$hydro_pre_prompt...all-the-other-vars...$hydro_post_prompt"
end
@jorgebucaran jorgebucaran added the enhancement New feature or request label Jun 17, 2022
@mattmc3 mattmc3 changed the title Spacious multi-line prompt Pre/Post prompt customization Jun 17, 2022
@jorgebucaran
Copy link
Owner

@mattmc3 What would you like to set these to in practice? I just want to see how the prompt would look.

@mattmc3
Copy link
Collaborator Author

mattmc3 commented Jun 18, 2022

Screen Shot 2022-06-17 at 9 29 27 PM

@mattmc3
Copy link
Collaborator Author

mattmc3 commented Jun 18, 2022

One more example using a post-prompt for to indicate a Python venv:

function VIRTUAL_ENV --on-variable VIRTUAL_ENV
    if test -n "$VIRTUAL_ENV"
        set -g fish_prompt_pwd_dir_length 1
        set -g hydro_pre_prompt ""
        set -g hydro_post_prompt "🐍 "
        set -g hydro_multiline false
    else
        set -g fish_prompt_pwd_dir_length -1
        set -g hydro_pre_prompt "\n"
        set -g hydro_post_prompt " "
        set -g hydro_multiline true
    end
end && VIRTUAL_ENV

Screen Shot 2022-06-17 at 9 50 33 PM

@jorgebucaran
Copy link
Owner

Thanks, @mattmc3. Would this feature also supersede hydro_multiline?

@mattmc3
Copy link
Collaborator Author

mattmc3 commented Jun 20, 2022

It could. In that case we'd need to deprecate/repurpose the multiline variable, and then if you wanted a more spacious prompt you'd do set --query hydro_pre_prompt || set --global hydro_pre_prompt "\n\n". Since deprecating a variable would be a breaking change, I'll leave that call to you.

@mattmc3
Copy link
Collaborator Author

mattmc3 commented Jun 20, 2022

See PR #36 for an alternative implementation that handles mutiline support.

@jorgebucaran
Copy link
Owner

Thank you, @mattmc3. I'm still not sure if I want to add this feature, but I'm thinking about it.

Question. Would a new "sparse" (as opposed to "compact") configuration variable solve your use case here? I'm not suggesting we add that yet, just curious.

@mattmc3
Copy link
Collaborator Author

mattmc3 commented Jun 29, 2022

The genesis of this request is from someplace else entirely. What I'm actually looking at is other prompts like Starship, which let you customize a ton of components of your prompt: https://starship.rs/config/#prompt. Starship isn't fast (at least, compared to Hydro), and I definitely don't think Hydro should become like Starship, but having a simple way to extend Hydro answers a lot of the customization need without putting additional burden on Hydro to support all-the-things the way the Starship devs have to.

The other option I was considering is forking out the clever git status portion of the prompt (similar to what Zsh has here: https://github.com/romkatv/gitstatus). Having these features separate would let Fish users compose a prompt of their choosing tailored to their specific needs, and makes the Ruby/Python/Node/Go/Rust/etc customizations available with a simple user-managed Fish script. This method seems overkill when Hydro does 95% of what I need in a prompt, but could use just a small hook or two to add customizations to it. Whitespace management is only one small part of that customization.

If there's another idea I hadn't considered, I'm open to that.

@jorgebucaran
Copy link
Owner

Fair enough. Should we also consider adding a right prompt?

@jorgebucaran
Copy link
Owner

Another option is introducing a new variable: $hydro_prompt_items. We would iterate over the list of items and figure out how to print the prompt from there. This would allow you not only to add new items but to reorder the built-in items.

set --global hydro_prompt_items _hydro_git _hydro_pwd _hydro_prompt
function fish_prompt --description Hydro
    if set --query hydro_prompt_items
        set --local prompt 
        for item in $hydro_prompt_items
            switch $item
                case _hydro_pwd
                    set prompt "$prompt$_hydro_color_pwd$_hydro_pwd$hydro_color_normal"
                case _hydro_git
                    set prompt "$prompt $_hydro_color_git$$_hydro_git$hydro_color_normal"
                case _hydro_cmd_duration
                    set prompt "$prompt$_hydro_color_duration$_hydro_cmd_duration$hydro_color_normal"
                case _hydro_prompt
                    set prompt "$prompt$_hydro_prompt$hydro_color_normal"
                case \*
                    echo set prompt "$prompt$_hydro_color_$$item$$item$hydro_color_normal"
            end
        end
        echo -e "$prompt "
    else
        echo -e "$_hydro_color_pwd$_hydro_pwd$hydro_color_normal $_hydro_color_git$$_hydro_git$hydro_color_normal$_hydro_color_duration$_hydro_cmd_duration$hydro_color_normal$_hydro_prompt$hydro_color_normal "
    end
end
main ~/C/@/hydro 1.3s ❱

@mattmc3
Copy link
Collaborator Author

mattmc3 commented Jul 1, 2022

I like that a lot. That’s a way better solution. Then the user just adds items, or overrides the prompt and displays the items themselves.

@jorgebucaran
Copy link
Owner

I think that's how Tide does it. I don't want to allow too much customization, though. I think Tide already excels at that.

Having said that, I'm not sure about this particular implementation yet. It's not slow, but it hurts perf a tiny bit, which I'd like to avoid or diminish somehow (if possible).

@jorgebucaran
Copy link
Owner

While I'm open to exploring the idea of addons, components, or whatever we want to call them (#37), I won't be introducing specific pre/post customization variables, so closing as not planned.

@jorgebucaran jorgebucaran closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants