[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#846237: ITP: ondir -- Automate tasks specific to certain directories in the shell



On 11/29/2016 04:23 PM, Julian Taylor wrote:
> On 11/29/2016 03:41 PM, Christian Seiler wrote:
>> (Forwarding because I forgot to Cc debian-devel@.)
>>
>> ondir is a small program to automate tasks specific to certain
>> directories. It works by executing scripts in directories when
>> you enter and leave them. It may be used to set environment
>> variables or change the umask depending on the current working
>> directory.
> 
> Seems very similar to the direnv package 

Oh, I didn't know that one, thanks for pointing me to it.

> except that direnv does not have an unload hook by design (e.g.
> what is done when the terminal is closed? I guess its up to the
> users script to handle that?)

The leave function is not executed with ondir when the shell
exits while in a given directory - only when cd'ing out. In
that sense I don't see any differences between direnv and
ondir.

> Are there any other notable differences?

direnv requires you to modify the directories themselves, ondir
has it's configuration in the home directory. That means that for
publicly shared directories ondir allows different configurations
per-user, while that is not easily possible with direnv.

Also, ondir can match arbitrary directories by pattern, the
README.md on github  an example configuration for the use with
virtual python environments:

enter ~/Projects/([^/]+)
  if [ -r .venv ]; then
    . ./.venv/bin/activate
  fi

leave ~/Projects/([^/]+)
  deactivate > /dev/null 2>&1

With direnv you'd need .envrc files in each of those directories.

ondir always includes the configuration for any parent directories,
while with you can decide that for yourself with direnv (according
to the documentation anyway).

direnv has a standard library for modifying environment variables
(such as PATH) already available, while you'd have to do that
yourself with ondir.

direnv appears to be quite verbose (without an apparent way to
turn it off), while ondir isn't, but you can be verbose yourself
there if you so wish.

They both support the same shells (bash, zsh, tcsh and fish).

As for further differences: I plan on enabling ondir by default
in the Debian package, but only if either a system wide or user
specific configuration exists (so users that don't care about
ondir won't see any change, but it works out of the box once the
user creates the configuration file for it); this is not possible
for direnv, as you can only know if that is used by the user if
they cd into a directory with a .envrc file.

> From the descriptions it seems that direnv might be the better choice
> is what you need is only environment setup and teardown and not
> execution of arbitrary commands, possibly that should be noted in the
> description so the user can decide.

I will add a reference to direnv to the description so users are
able to make up their mind as to what solution is the better one
for them. (There are both advantages and disadvantages to either
approach.)

Thanks again for pointing the alternative out.

Regards,
Christian


Reply to: