Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Using `find` for tab completion: allow organizing projects in subdirectories of $WORKON_HOME

30 views
Skip to first unread message

Alex Buchanan

unread,
May 15, 2013, 11:11:13 PM5/15/13
to virtuale...@googlegroups.com
I've tweaked virtualenvwrapper.sh slightly, and I'm posting here in case anyone is interested.

Background: I have lots of projects. Some are related to a group, so it's natural to group them into a directory.

Example: mkproject some-group/some-project

This works for mkproject, cool! Tab completion for the workon command didn't work though.

So I tweaked line 532 of virtualenvwrapper.sh to use find instead of echo. Seems to work so far.

- echo $WORKON_HOME/*/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate
+ find $WORKON_HOME -wholename "*/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate"

Cheers.


Alex Buchanan

unread,
May 21, 2013, 1:04:21 PM5/21/13
to virtuale...@googlegroups.com
Using find is pretty slow however. Anybody have ideas for how to have a recursive search and be fast?

Julie Jones

unread,
Jan 30, 2016, 4:44:57 PM1/30/16
to virtualenvwrapper
If you are willing to limit the depth of the find to a specific number of levels (your example has group/project) then you can use "find <root> -maxdepth 2"  or something similar.

Doug Hellmann

unread,
Jan 30, 2016, 6:05:19 PM1/30/16
to virtuale...@googlegroups.com
On Jan 30, 2016, at 4:44 PM, Julie Jones <julie7...@gmail.com> wrote:

If you are willing to limit the depth of the find to a specific number of levels (your example has group/project) then you can use "find <root> -maxdepth 2"  or something similar.

There’s a comment in the code that “echo seems a little faster than find, even with -depth 3” but I don’t remember how much difference there really was. It would be interesting to see some numbers, if someone could put together a test.

I wonder if some sort of flag is in order, to control whether a depth search is performed or not. For example, setting VIRTUALENVWRAPPER_PROJECT_SEARCH_DEPTH to some value > 0 could trigger using find instead of echo, and then the find maxdepth argument could be computed based on the value given (it might need to be 2 more than the value given to account for the bin directory and activate script that we’re looking for).

All of that might be more complex than needed, too. We could just switch to using compgen -d more directly. It would result in false positives if there are directories under $WORKON_HOME that aren’t actually virtualenvs, but maybe that’s not such a big deal.

Thoughts?

Doug


On Tuesday, May 21, 2013 at 11:04:21 AM UTC-6, Alex Buchanan wrote:
Using find is pretty slow however. Anybody have ideas for how to have a recursive search and be fast?

On Wednesday, May 15, 2013 8:11:13 PM UTC-7, Alex Buchanan wrote:
I've tweaked virtualenvwrapper.sh slightly, and I'm posting here in case anyone is interested.

Background: I have lots of projects. Some are related to a group, so it's natural to group them into a directory.

Example: mkproject some-group/some-project

This works for mkproject, cool! Tab completion for the workon command didn't work though.

So I tweaked line 532 of virtualenvwrapper.sh to use find instead of echo. Seems to work so far.

- echo $WORKON_HOME/*/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate
+ find $WORKON_HOME -wholename "*/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate"

Cheers.



-- 
You received this message because you are subscribed to the Google Groups "virtualenvwrapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to virtualenvwrap...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages