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

Introduce add-ons #37

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Introduce add-ons #37

wants to merge 3 commits into from

Conversation

jorgebucaran
Copy link
Owner

Addons let you add new components to your Hydro prompt. They're not as flexible as Tide items (and don't intend to be). My goal is not to reinvent Tide, but still allow a degree of configuration not possible right now. For example, maybe I'd want to display the current Node version using nvm.

Creating an addon is easy:

function _hydro_addon_node
    echo (set_color yellow) ⍺ (nvm current)(set_color normal)
end

Then in config.fish:

set --global hydro_prompt_addons node

hydro

Closes #34 #35 #36

@jorgebucaran jorgebucaran added the enhancement New feature or request label Jul 2, 2022
@nathanchance
Copy link

I ended up taking this for a spin, as it would allow me to move a lot of my out of tree customizations out of Hydro and into my own dotfiles. The only issue I have noticed is that the addons do not work until I move into a git repository, as $_hydro_addons is only set in _hydro_prompt after the check for _hydro_skip_git_prompt, if I am reading everything correctly.

@jorgebucaran
Copy link
Owner Author

Yep, should be fixed now! 💯

@nathanchance
Copy link

Thanks, looks good to me!


set --query _hydro_skip_git_prompt && set $_hydro_git && return
command kill $_hydro_last_pid 2>/dev/null

fish --private --command "
Copy link

@simontong simontong Jul 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we are defining the prompt in private mode, it doesn't appear possible to conditionally display a character in the prompt if we are in private mode. Could we introduce an additional global variable (something like is_fish_private_mode) that gets set just before we enter private mode in the code above? Then we can have the following addon in the prompt:

set --global hydro_prompt_addons private

function _hydro_addon_private
  if test "$is_fish_private_mode" = 1
    echo [p]
  end
end

The above would result in the prompt:

/home/johnsmith/abc > fish -P
/home/johnsmith/abc [p] >

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may not even need --private mode to be honest! 🤔

Copy link
Collaborator

@mattmc3 mattmc3 Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to change anything in Hydro to handle this particular addon example. In your config.fish, you can just check that the shell is interactive so that subshells that run your config (like those Hydro creates) don't nuke your flag. This code will do what you want with the current implementation:

# config.fish
status --is-interactive && set --export is_fish_private_mode $fish_private_mode
function _hydro_addon_private
    if test "$is_fish_private_mode" = 1
        echo [p]
    end
end
set --global hydro_prompt_addons private

I like having Hydro use --private so it doesn't clutter your fish history with all the non-user git commands it fires off, but that's not a huge deal either way. But, if this is work-around is acceptable, we can leave --private in and everyone wins.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I concur!

@dangh
Copy link

dangh commented Jul 20, 2022

Would it be possible to turn the existing components to pre-built addons? I would like to display the git branch conditionally. I'm using git worktree and the directory is named after the git branch so it's kinda redundant there.

This feature is awesome nonetheless. Thank you so much for making it.

@jrop
Copy link

jrop commented Oct 13, 2022

Having this system merged would be fantastic: I want to create an add-on for myself that displays the host name if any of the SSH_* vars are set.

Edit: I tested this branch out as well, and it works perfectly for what I want to accomplish:

function _hydro_addon_ssh
  if test -n "$SSH_CLIENT"
    echo (set_color yellow)🌐:(hostname)(set_color normal)
  end
end

set -g hydro_prompt_addons ssh

@jorgebucaran
Copy link
Owner Author

I think that having this would be fantastic too, but the code required to implement this was non-trivial and my implementation is not great either. The more of these little addons you create the slower your terminal gets.

@brandonpittman
Copy link

The more of these little addons you create the slower your terminal gets.

While I love the idea of these, I was also concerned about how they could slow down the terminal.

@jorgebucaran
Copy link
Owner Author

This runs addons inside a subshell, which is better than nothing, but we'd really want to run each addon in its own subshell.

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 this pull request may close these issues.

Pre/Post prompt customization
7 participants