Skip to content

Commit

Permalink
Merge pull request #4 from Galooshi/fix-PATH
Browse files Browse the repository at this point in the history
Grab PATH on plugin initialization
  • Loading branch information
trotzig committed May 14, 2016
2 parents 0513bf2 + fd55fd3 commit 7ee84f6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
45 changes: 36 additions & 9 deletions import-js.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,41 @@
import sublime_plugin
import subprocess

import_js_environment={}

def extract_path():
# We have to delimit the PATH output with markers because
# text might be output during shell startup.
out = subprocess.Popen(
[os.environ['SHELL'], '-l', '-c',
'echo "__SUBL_PATH__${PATH}__SUBL_PATH__"'],
env=os.environ,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
).communicate()[0].decode()
path = out.split('__SUBL_PATH__', 2)

if len(path) > 1:
return path[1]

return ''

def plugin_loaded():
global import_js_environment

import_js_environment = dict(os.environ).copy()
import_js_environment.update({
'LC_ALL': 'en_US.UTF-8',
'LC_CTYPE': 'UTF-8',
'LANG': 'en_US.UTF-8',
})

import_js_environment.update({
'PATH': extract_path(),
})

print('ImportJS loaded with environment:')
print(import_js_environment)

def no_executable_error(executable):
return dedent('''
Expand All @@ -25,7 +60,6 @@ def no_executable_error(executable):
from the command line in your project's root.
'''.format(executable=executable)).strip()


class ImportJsReplaceCommand(sublime_plugin.TextCommand):
def run(self, edit, characters):
self.view.replace(
Expand All @@ -37,13 +71,6 @@ def run(self, edit, **args):
current_file_contents = self.view.substr(
sublime.Region(0, self.view.size()))

environment = dict(os.environ).copy()
environment.update({
'LC_ALL': 'en_US.UTF-8',
'LC_CTYPE': 'UTF-8',
'LANG': 'en_US.UTF-8',
'PATH': environment.get('PATH') + ':/usr/local/bin'
})
project_root = self.view.window().extract_variables()['folder']
settings = sublime.load_settings('ImportJS.sublime-settings')

Expand All @@ -66,7 +93,7 @@ def run(self, edit, **args):
proc = subprocess.Popen(
command,
cwd=project_root,
env=environment,
env=import_js_environment,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
Expand Down
3 changes: 2 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"0.4.0": "sublime-messages/v0.4.0.txt",
"0.5.0": "sublime-messages/v0.5.0.txt",
"0.6.0": "sublime-messages/v0.6.0.txt",
"0.7.0": "sublime-messages/v0.7.0.txt"
"0.7.0": "sublime-messages/v0.7.0.txt",
"0.7.2": "sublime-messages/v0.7.2.txt"
}
6 changes: 6 additions & 0 deletions sublime-messages/v0.7.2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Version 0.7.2 makes the plugin better at finding your `PATH` environment
variable. If you have changed the "exectuable" setting to work around not finding
`node` or `importjs`, you might be able to remove that workaround now.

As always, you should also update the import-js binary by running
`npm install -g import-js`

0 comments on commit 7ee84f6

Please # to comment.