mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-05-08 04:34:00 +02:00
Adding plugin node-modules-path
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.
This commit is contained in:
parent
291e96dcd0
commit
708f3a51bc
2 changed files with 67 additions and 0 deletions
28
plugins/node-modules-path/path_check.py
Normal file
28
plugins/node-modules-path/path_check.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue