sheldon icon indicating copy to clipboard operation
sheldon copied to clipboard

Conditional sourcing

Open denysdovhan opened this issue 3 years ago • 3 comments

I'd love to some kind of when option in the config file, for conditional sourcing. For example, I had this configuration with zplug

if [[ -d "$HOME/Projects/Repos/spaceship/spaceship-prompt" ]]; then
  zplug "$HOME/Projects/Repos/spaceship/spaceship-prompt", from:local, as:theme, use:"spaceship.zsh"
else
  zplug "denysdovhan/spaceship-prompt", as:theme, use:"spaceship.zsh"
fi

I guess it's possible to make something like this in sheldon:

[plugins.spaceship]
github = 'spaceship-prompt/spaceship-prompt'
when = 'test ! -d "$HOME/Projects/Repos/spaceship/spaceship-prompt"'

[plugins.spaceship-local]
local = '$HOME/Projects/Repos/spaceship/spaceship-prompt'
when = 'test ! -d "$HOME/Projects/Repos/spaceship/spaceship-prompt"'

In the example above, when option will execute the command. Entry will be sourced if it was executed with zero exit code. Additionally a skip command might be introduced to do the opposite.

denysdovhan avatar Jul 08 '21 15:07 denysdovhan

Quick thought: It can also be used to conditionally load plugins for bash and zsh on different machines.

denysdovhan avatar Jul 08 '21 16:07 denysdovhan

This would be really useful when you try to load plugins specific to OSTYPE

TheCodeDestroyer avatar Nov 12 '21 11:11 TheCodeDestroyer

I'd really appreciate this feature :)

Laura7089 avatar Jul 15 '22 19:07 Laura7089

Resolved in #143

rossmacarthur avatar Oct 13 '22 11:10 rossmacarthur