jorgebucaran / hydro

Ultra-pure, lag-free prompt with async Git status—just for Fish
MIT License
697 stars 53 forks source link

Introduce add-ons #37

Open jorgebucaran opened 2 years ago

jorgebucaran commented 2 years ago

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

nathanchance commented 2 years ago

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 commented 2 years ago

Yep, should be fixed now! 💯

nathanchance commented 2 years ago

Thanks, looks good to me!

dangh commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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