Skip to content
This repository has been archived by the owner on Oct 30, 2021. It is now read-only.

Commit

Permalink
Removed PATH from settings, can still be used to override system PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
tvooo committed Oct 10, 2013
1 parent f612732 commit 3d69773
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
13 changes: 11 additions & 2 deletions README.md
Expand Up @@ -18,8 +18,16 @@ As of version 0.2, there is also a command to kill running tasks, for example
## Settings

The file `SublimeGrunt.sublime-settings` is used for configuration.
You may have to add the path to your Node.js installation to the `path`
variable.

You may override your `PATH` environment variable as follows:

```
{
"exec_args": {
"path": "/bin:/usr/bin:/usr/local/bin"
}
}
```

## Releases

Expand All @@ -34,3 +42,4 @@ Thanks for some contributions go to
* [structAnkit](https://github.com/structAnkit)
* [lavrton](https://github.com/lavrton)
* [adamcbrewer](https://github.com/adamcbrewer)
* [thebjorn](https://github.com/thebjorn)
4 changes: 1 addition & 3 deletions SublimeGrunt.sublime-settings
@@ -1,5 +1,3 @@
{
"exec_args": {
"path": "/bin:/usr/bin:/usr/local/bin"
}
"exec_args": {}
}
23 changes: 16 additions & 7 deletions main.py
Expand Up @@ -17,25 +17,29 @@ def __init__(self, window):
self.list_gruntfiles()

def list_tasks(self):
path = settings().get('exec_args').get('path')
path = get_env_path()
package_path = os.path.join(sublime.packages_path(), package_name)
args = 'grunt --no-color --tasks "' + package_path + '" expose'

(stdout, stderr) = subprocess.Popen(args, stdout=subprocess.PIPE, env={"PATH": path}, cwd=self.wd, shell=True).communicate()
stdout = stdout.decode('utf8')
if stderr:
stderr = stderr.decode('utf8')
else:
stderr = u''
json_match = regex_json.search(stdout)

if json_match is not None:
try:
json_result = json.loads(json_match.groups()[0])
except TypeError:
self.window.run_command("grunt_error", {"message": "SublimeGrunt: JSON is malformed\n\n" + json_match.groups()[0]})
self.window.new_file().run_command("grunt_error", {"message": "SublimeGrunt: JSON is malformed\n\n" + json_match.groups()[0]})
sublime.error_message("Could not read available tasks\n")
else:
tasks = [[name, task['info'], task['meta']['info']] for name, task in json_result.items()]
return sorted(tasks, key=lambda task: task)
else:
self.window.run_command("grunt_error", {"message": "SublimeGrunt: Could not expose available tasks\n\n" + stdout})
self.window.new_file().run_command("grunt_error", {"message": "SublimeGrunt: Could not expose available tasks\n\n" + stdout + "\n\n" + stderr})
sublime.error_message("Could not expose available tasks\n")

def list_gruntfiles(self):
Expand Down Expand Up @@ -63,13 +67,18 @@ def choose_file(self, file):

def on_done(self, task):
if task > -1:
exec_args = settings().get('exec_args')
exec_args.update({'cmd': "grunt --no-color " + self.tasks[task][0], 'shell': True, 'working_dir': self.wd})
exec_args = {'cmd': "grunt --no-color " + self.tasks[task][0], 'shell': True, 'working_dir': self.wd}
self.window.run_command("exec", exec_args)


def settings():
return sublime.load_settings('SublimeGrunt.sublime-settings')
def get_env_path():
path = os.environ['PATH']
settings = sublime.load_settings('SublimeGrunt.sublime-settings')
if settings:
exec_args = settings.get('exec_args')
if exec_args:
path = exec_args.get('path', os.environ['PATH'])
return str(path)


class GruntCommand(sublime_plugin.WindowCommand):
Expand Down

0 comments on commit 3d69773

Please sign in to comment.