I have a envrc I want to apply to my home directory but not subdirectories. For example this is currently how direnv works:
I don't want /home/zach/.envrc to apply to /home/zach/some_project_without_envrc. I looked at docs, and didn't see anything about this.
I also looked through the source, and found where I could change this behavior, and I was hack this feature in pretty quickly. I could open a PR, is this a feature direnv would be interested in? I assumed it'd be best to make this configurable by creating a section in config.toml file, so I could make something like:
skip_subdirectories = ["/home/zach"]
Or am I missing an easier way to achieve this result?
Is there any case where you want other .envrc to be loaded or is it only in the home directory?
If the goal is to change the user configuration the best approach is to use the .bash_profile or other shell-level configuration directly.
Yes I use envrc's in some of my projects, but not all. I want to set special behavior for my home, but I don't want it to apply to projects under the home tree that don't have an envrc.
If there are more users that want this feature I would be willing to add it. By default I would prefer to keep direnv simple.
How about moving your projects under $HOME/code and then add an empty .envrc in $HOME/code?
How about moving your projects under $HOME/code and then add an empty .envrc in $HOME/code?
Ahh I knew there was a simple solution I was missing, that would totally work.
If there are more users that want this feature I would be willing to add it. By default I would prefer to keep direnv simple.
Will really appreciate the possibility to have .envrc specific to some directory without been available in updirs
My use case is as follow :
Dotfiles resides in a git repository
I have in PS1 the git status when i'm in a repository
So, to see any changes in my dotfiles when i'm on ~/, i tried to set in ~/.envrc
export GIT_DIR=$HOME/.local/opt/dotfiles/.git
export GIT_WORK_TREE=$HOME
But having this set have as a consequence to have all my git commands targetting the same repository... :cry:
Regards,
Edit:
In the meantime, my workaround is to add my own env loading function in PROMPT_COMMAND
_check_dotfiles_gitdir() {
local dotfiles_gitdir="${HOME}/.local/opt/dotfiles/.git"
if [[ "${PWD}" == "${HOME}" ]];then
export GIT_DIR="${dotfiles_gitdir}"
export GIT_WORKTREE="${HOME}"
else
[[ "${GIT_DIR}" == "${dotfiles_gitdir}" ]] && unset GIT_DIR
[[ "${GIT_WORKTREE}" == "${HOME}" ]] && unset GIT_WORKTREE
fi
}
if ! [[ "$PROMPT_COMMAND" =~ _check_dotfiles_gitdir ]]; then
PROMPT_COMMAND="_check_dotfiles_gitdir;$PROMPT_COMMAND";
fi
Most helpful comment
If there are more users that want this feature I would be willing to add it. By default I would prefer to keep direnv simple.
How about moving your projects under $HOME/code and then add an empty .envrc in $HOME/code?