Coder Social home page Coder Social logo

Comments (7)

grigorii-horos avatar grigorii-horos commented on June 16, 2024

Mmm... Very interesting.
For example, I have ~/Projects/node, and .in file in ~/Projects. When I execute cd ~/Projects/node, this plugin execute .in file.
Can you provide your dir structure, and .in file?

from autoenv.

piether avatar piether commented on June 16, 2024

Here's a concrete example:

$ tree test/
test/
├── project-a
└── project-b

2 directories, 0 files
$ cat test/.in
echo "Adding $PWD/node_modules/bin to the PATH"
$ cd test/project-a 
Adding /home/pieter/test/project-a/node_modules/bin to the PATH
$ cd ../project-b
$ 

Nothing happens when I cd ../project-b while what I would like to happen is that it would execute the test/.in file again.

from autoenv.

grigorii-horos avatar grigorii-horos commented on June 16, 2024

@piether Are you sure that you need this behaviour? You already have $PWD/node_modules/bin in your $PATH, and sourcing this file again will produce duplicates in your $PATH.

from autoenv.

piether avatar piether commented on June 16, 2024

But the value of $PWD is different when I change directories, so the expression needs to be re-evaluated, no? I didn't bother including an .out file but I would avoid duplicates in the PATH that way.

Here's an even more elaborated example of my problem:

test/.in:

echo "Adding $PWD/node_modules/bin to the PATH"
export PATH=$PWD/node_modules/bin:$PATH
echo "New PATH: $PATH" 
$ tree test/
test/
├── project-a
└── project-b
    └── node_modules
        └── bin
            └── grunt

4 directories, 1 file
$ cd test/project-a
Adding /home/pieter/test/project-a/node_modules/bin to the PATH
New PATH: /home/pieter/test/project-a/node_modules/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ cd ../project-b
$ grunt
zsh: command not found: grunt
$ cd /                                                                                                                                        127 ↵
$ cd ~/test/project-b
Adding /home/pieter/test/project-b/node_modules/bin to the PATH
New PATH: /home/pieter/test/project-b/node_modules/bin:/home/pieter/test/project-a/node_modules/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ grunt
$ 

So the project-b/bin directory is only on the PATH after I cd / and then go back into it.

from autoenv.

grigorii-horos avatar grigorii-horos commented on June 16, 2024

@piether I understand you. It's a bug in the plugin. For file ~/Projects/.in, when you execute cd ~/Projects/project, $PWD need to be ~/Projects, but not ~/Projects/project

from autoenv.

piether avatar piether commented on June 16, 2024

After thinking about it once more, I conclude:

  • you can put common stuff in parent directory .in and .out files that are not related to the exact location you cd into. E.g. an AWS_PROFILE for all projects for a certain customer
  • if you want to set something that is related to the exact location, you need an explicit .in and .out in each directory where you want this behaviour.

from autoenv.

grigorii-horos avatar grigorii-horos commented on June 16, 2024

@piether I make a mistake in my comment. it's normal behaviour of $PWD. Instead of using $PWD in .in files, you need to use $(dirname $0)/your_path_with_bin. So, you can use something like this

for node_path in $(dirname $0)/*/node_modules/.bin; do
  export PATH=$PATH:$node_path
done

from autoenv.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.