romkatv/zsh-defer

When defering direnv load, it isn't working (it should call .envrc when we change dir) inside VSCode's integrated terminal

Closed this issue · 17 comments

Workaround is to add -m to zsh-defer
See https://github.com/direnv/direnv

Could you provide more details? What do you do, what do you expect and what do you observe?

When I add zsh-defer eval "$(direnv hook zsh)" to ~/.zshrc, it works just like the plain eval "$(direnv hook zsh)". The only difference is that the output to stdout/stderr is suppressed during initialization, which is the expected behavior.

Inside VSCode integrated terminal ? Outside it works.

Inside VSCode integrated terminal ?

Yes.

Could you provide more details? What do you do, what do you expect and what do you observe?

I've also verified that zsh-defer -m eval "$(direnv hook zsh)" (with -m) does not work. Specifically, if the current directory contains .envrc, this file does not get sourced when zsh starts. If direnv is loaded with zsh-defer eval "$(direnv hook zsh)" (without -m) or eval "$(direnv hook zsh)", this file does get sourced. All of these are expected.

Do you garante order if i do zsh-defer one.sh and zsh-defer two.sh ? Will two.sh be evaluated after one.sh or they occur in parallel ? That may be my issue ... thanks!

Do you garante order if i do zsh-defer one.sh and zsh-defer two.sh ?

Yes. From the docs:

Deferred commands are put in a queue (FIFO). Whenever zle is idle, the next command is popped from the queue.


Will two.sh be evaluated after one.sh or they occur in parallel ?

Nothing gets evaluated in parallel. All commands are executed in the main zsh thread.

That may be my issue ... thanks!

If you could explain how to reproduce this (what you do, what you observe and what you expect), I can take care of the rest. Guessing what's wrong may take a very long time.

I defer 'eval "$(direnv hook zsh)"' and I have a .envrc that does '. $KERL_DEFAULT_INSTALL_DIR/21.3/activate'
But it doesn't activate the erlang version, it also should export some vars but it also doesn't. Its doen't work inside VSCode's terminal. Outside works as expected. The only workaround I have is to call defer with -m.

I have to investigate further. Thanks for the support!

Could you post your ~/.zshrc?

Could you describe the steps you perform in VSCode? What do you click, what do you type, what do you observe?

~/.zshrc:

#!/bin/sh

# Source global definitions
if [ -f /etc/zshrc ]; then
	. /etc/zshrc
fi

source ~/.zsh-defer/zsh-defer.plugin.zsh

# see https://chr4.org/blog/2014/09/10/conf-dot-d-like-directories-for-zsh-slash-bash-dotfiles/
export SHELL_EXTENSION=zsh
if [ -d $HOME/.zshrc.d ]; then
    for file in $HOME/.zshrc.d/*.$SHELL_EXTENSION; do
        source $file
    done
fi
if [ -d $HOME/.rc.d ]; then
    for file in $HOME/.rc.d/*.sh; do
        zsh-defer -m source $file
    done
fi

~/.rc.d/direnv.sh:

# return if requirements are not found.
if [ ! -x "$(command -v direnv)" ]; then
    return 1
fi
# see https://github.com/direnv/direnv
eval "$(direnv hook $SHELL_EXTENSION)"

~/.rc.d/kerl.sh:

[ -f "${HOME}/.kerlrc" ] && \
    source "${HOME}/.kerlrc"

~/.kerlrc:

export KERL_BASE_DIR=$HOME/.kerl
export KERL_DEFAULT_INSTALL_DIR=$KERL_BASE_DIR/installs

.envrc:

. $KERL_DEFAULT_INSTALL_DIR/21.3/activate

Complete dotfiles in https://github.com/rjcoelho/dotfiles.rcm.

Your code is sourcing files in lexicographical order. Thus, ~/.rc.d/direnv.sh is sourced before ~/.rc.d/kerl.sh. When ~/.rc.d/direnv.sh is sourced, .envrc tries to source $KERL_DEFAULT_INSTALL_DIR/21.3/activate but KERL_DEFAULT_INSTALL_DIR is not set because ~/.rc.d/kerl.sh hasn't been sourced yet.

Yes I that could be it, but then it shouldn't also work outside vscode. Anyway I need to force an order, probably we prefix files by a number. Let me see

Yes thats it .. a simple rename to _kerl.sh did the trick, Thanks!!

Thanks for the confirmation.

Btw this lib is the great!! I'm just now trying to defer the remaining sh files (zim/prompt/autosuggestions/...)

Glad you find it useful.

FWIW, I'm not using it myself because there is a much better alternative (powerlevel10k with instant prompt).

@romkatv Are the instant prompt scripts independent of the rest of powerlevel10k? Did you try either deferring zimfw to have an idea why deferring has side effects as observed at zimfw/zimfw#372 (comment) ?

@romkatv Are the instant prompt scripts independent of the rest of powerlevel10k?

No.

Did you try either deferring zimfw

No.

[...] side effects as observed at zimfw/zimfw#372 (comment) ?

If you believe there is a bug in zsh-defer or need help with using it, please open an issue at zsh-defer.