708f3a51bc
If chpwd is changed to a path where any folder within that subpath contains a node_modules folder, then that path + .bin is added to the PATH env variable. The reason for writing this plugin is that I often open up atom directly from the shell in a directory of interest. If I have flow installed locally then I have to add the node_modules folder in that path to PATH before I open up Atom.
29 lines
652 B
Python
29 lines
652 B
Python
import os
|
|
import sys
|
|
|
|
def get_subpaths(path):
|
|
paths = []
|
|
dirs = path.split('/')[1:]
|
|
|
|
for i in range(len(dirs), 0, -1):
|
|
p = os.path.join(*dirs[0:i])
|
|
yield p
|
|
|
|
def has_modules_folder(path):
|
|
check_path = os.path.join('/', path, 'node_modules')
|
|
return os.path.exists(check_path) and os.path.isdir(check_path)
|
|
|
|
def get_closes_path_dir(path):
|
|
for p in get_subpaths(path):
|
|
if has_modules_folder(p):
|
|
return '/' + p
|
|
return ''
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) == 1:
|
|
sys.exit(1)
|
|
else:
|
|
path = sys.argv[1]
|
|
print get_closes_path_dir(path)
|
|
sys.exit(0)
|