Skip to content
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

Provide a way to access the default cd #17

Closed
d0ugal opened this issue Feb 29, 2012 · 4 comments
Closed

Provide a way to access the default cd #17

d0ugal opened this issue Feb 29, 2012 · 4 comments

Comments

@d0ugal
Copy link

d0ugal commented Feb 29, 2012

I wanted to add this to my .env file;

PROJECT_NAME="$( basename "$( cd "$(dirname "${BASH_SOURCE}" )" && pwd )")";

However, as you can see the line includes a call to cd because of this, the script enters an infinite loop and hangs.

I'm not actually sure if/how this can be improved.

@d0ugal
Copy link
Author

d0ugal commented Feb 29, 2012

FWIW, I worked around this by making a call out to zsh as shown in line 2 of the following.

PROJECT_DIR="$(dirname "${BASH_SOURCE:-$0}" )";
ABSOLUTE_DIR=`$SHELL -c "cd \"$PROJECT_DIR\" && pwd"`;
PROJECT_NAME="$( basename $ABSOLUTE_DIR)";

if [[ -n $PROJECT_NAME && $VIRTUAL_ENV != *"$PROJECT_NAME" ]];
    then workon $PROJECT_NAME;
fi;

unset PROJECT_DIR;
unset ABSOLUTE_DIR;
unset PROJECT_NAME;

@nvie
Copy link
Contributor

nvie commented Mar 29, 2012

You can use:

builtin cd /path/to/dir

@d0ugal
Copy link
Author

d0ugal commented Mar 29, 2012

Oh neat, I had no idea. Thanks!

@d0ugal d0ugal closed this as completed Mar 29, 2012
@hansbogert
Copy link

When I use the builtin, then autoenv still executes my .env script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants