-
Notifications
You must be signed in to change notification settings - Fork 14
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
Config plugin specific settings right away after loading it #84
Comments
While I like this idea and use it myself in my neovim config I wouldn't see this feature in the scope of zgenom. However it would be a perfect match for an extension. If you don't expect the config to appear in the init.zsh right next to the plugin but at the end of the file it would be quite simple to implement as well. Would you be interested in writing such an extension yourself? |
This would be ok for most simple cases but there are many plugins need some environment variables or other configs to be set before loading them, and also might lead to other unexpected behaviors if the order can't be preserved. However it's still possible to implement without messing up with # heredoc only
zgenom-eval() {
setopt errreturn
local dir temp name
dir=$(zgenom api clone_dir inline)
temp=$(mktemp)
tee "$temp" >/dev/null
name="$(sha1sum "$temp" | cut -c 1-7).zsh"
mv "$temp" "$dir"/"$name"
zgenom load inline "$name"
} This is also useful in conjunction with some tools written in other languages, like
or some commands generate completion functions by themself. So perhaps it's also worth to build into This way is still not as simple and intuitive as writing normal zsh statement,what about writing all these in a separate file like |
If a deterministic name is created zgenom could be told to not clean up this file while it's used. (Adding the path to Even within zgenom the order of all commands isn't stored. In theory a I see three versions:
I don't think that 2. can be achieved in a nice way. The 1. is a bit clunky and in the end the order is only partially restored since it happens before or after all plugins and not in between plugins. |
My apologies for the late reply.
I think processing But I have another idea: If we can't use vanilla syntax for custom statements, how about doing it in other way around, keep custom statements as is but use special syntax for loading plugins. We can templating the # write what ever here will be preserved as is in the init.zsh file
export SOMETHING_TO_SET=1
# will expanded to concrete plugin loading statement
$(zgenom load zsh-users/zsh-history-substring-search)
# for just time comsuming tasks without evaluating anything
$(rbenv rehash > /dev/null)
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down And this will become much simpler to implement, since it's just ordinary "shell template". Or more over, to disambiguate with shell syntax, there are other templating engine available in shell, like https://github.com/jirutka/esh. |
It is. The As for your idea with the "vanilla syntax", while this might solve some of the issues it sounds like a lot of added complexity for something that would probably be a niche feature.
This would load the shell into the current session but wouldn't add anything to the init file. So it would either be slow or the whole |
Please try out this version: zgenom-eval() {
setopt errreturn
local dir temp name
temp=$(mktemp)
tee "$temp" >/dev/null
name="$(sha1sum "$temp" | cut -c 1-7)"
repo="inline/$name"
dir=$(zgenom api clone_dir $repo)
[[ ! -e $dir ]] && mkdir -p $dir
mv "$temp" "$dir"/init.zsh
zgenom load $repo
} Now everything should be cleaned up correctly. |
I mean using This may need some refactor of # in zgenom-load
ZERO="${source_file}" source "${source_file}"
# in zgenom-save
__zgenom_write "ZERO=${(qqq)file} source ${(qqq)file}"
to something roughly: __source_plugin(){
# figure out how to source a plugin
local output='ZERO="${source_file}" source "${source_file}"'
if [[ -n "${ZGENOM_RUNNING_IN_SAVE}" ]]; then
echo "$output"
else
eval "$output"
fi
}
# in zgenom-load
__source_plugin $plugin
# in zgenom-save
ZGENOM_RUNNING_IN_SAVE=1
...
__source_plugin $plugin same applied for fpath and prezto stuff. And then replace only the loading part in __zgenom_write "$(expand-template .zgenomrc)" naively expand-template(){
local name=$1 temp
temp=$(mktemp)
echo "cat <<EOF" >> $temp
cat $name >> $temp
echo "" >> $temp
echo "EOF" >> $temp
source $temp
} zgenomrc: $(zgenom load zsh-users/zsh-history-substring-search)
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
#$(rbenv rehash && echo "rehashed") expanded to init.zsh: # head added by zgenom
...
zsh_loaded_plugins+=( "zsh-users/zsh-history-substring-search" )
ZERO="zsh-users/zsh-history-substring-search/___/zsh-history-substring-search.plugin.zsh" source "zsh-history-substring-search/___/zsh-history-substring-search.plugin.zsh"
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
#rehashed
...
# foot added by zgenom Not very complicated, but it's different from current approch of |
Yes this worked very well. In my first comment I'm feeling a little overwhelm to create a whole repo for just a snippet so I used single file, but that's indeed OK, a folder is not really weight. |
With complexity I didn't necessarily hard to implement but it's a completely different api from the existing one. For the existing api of zgenom I find |
Please check out https://github.com/jandamm/zgenom-ext-eval. |
This allows ```zsh zgenom load zsh-users/zsh-history-substring-search zgenom eval <<EOF bindkey '^[[A' history-substring-search-up bindkey '^[[B' history-substring-search-down EOF zgenom eval --name zoxide <<(zoxide init zsh) ``` Closes #84
This allows ```zsh zgenom load zsh-users/zsh-history-substring-search zgenom eval <<EOF bindkey '^[[A' history-substring-search-up bindkey '^[[B' history-substring-search-down EOF zgenom eval --name zoxide <<(zoxide init zsh) ``` Closes #84
Many plugins need specific configurations, bug zgenom can't determine them.
For example:
the
bindkey
lines didn't appear in the generated init.zsh file, thus need to be written elsewhere,separate coupled code into different places makes them harder to maintain.Being able to config plugin settings just after loading it is more intuitive, and easier to add/remove/debug them.
Maybe this can be done by a command to construct and load an "inline plugin", like
or with heredoc
Even better, just write normal zsh statements without any special syntax,and let zgenom automatically add these statements to the generated init.zsh file as is.
The text was updated successfully, but these errors were encountered: