如何在将一个目录下自动运行bash脚本?

如何在将一个目录下自动运行bash脚本?

问题描述:

我所有的沙盒我与RVM和打捆项目,所以他们都很好地独立和他们所有的依赖关系可以保存在源代码控制。在其中的一个,我运行与保存在/ bin文件夹的垃圾桶项目。因此,我需要把它添加到PATH变量。但是,我想这是一个文件,是该项目的路线来完成,所以它的自动完成。

I'm sandboxing all of my projects with rvm and bundler, so they are all nicely standalone and all of their dependencies can be kept in source control. IN one of them, i run the project with a bin that is kept in the /bin folder. I therefore need to add this to the PATH variable. However, i'd like this to be done in a file that is in the project route, so it's done automatically.

下面是我的脚本,它是在一个名为.runme的文件:

Here's my script, which is in a file called ".runme":

# .runme
# add local bin folder to PATH unless it's already in there
function __bin_dir {
  echo "`pwd`/bin"
}
function __have_bin {
  echo $PATH | grep "^$(__bin_dir)"
}
[ "$(__have_bin)" == "" ] && export PATH=$(__bin_dir):$PATH

我能得到这个要去它在文件夹中自动运行?

Can i get this to run automatically on going to the folder it's in?

如果你能够的东西添加到需要此功能每一个用户的的.bashrc 文件,你也许可以挂接到 CD 操作来检查你所需要的。

If you're able to add stuff to the .bashrc file of every user that needs this functionality, you can probably hook into the cd operation to check for what you need.

有是关于如何挂钩到其他太问题CD 操作:有在Bash中一个钩子,找出CWD更改时?

There's another SO question about how to hook into the cd operation: Is there a hook in Bash to find out when the cwd changes?

我不熟悉的RVM,但他们似乎对挂接到 CD 一些文档:的 https://rvm.beginrescueend.com/workflow/hooks/

I'm not familiar with RVM, but they seem to have some documentation on hooking into cd: https://rvm.beginrescueend.com/workflow/hooks/