Skip to content

Commit

Permalink
embedding the installation
Browse files Browse the repository at this point in the history
  • Loading branch information
ticcky committed Nov 19, 2013
1 parent 85fa488 commit faa04f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 19 additions & 2 deletions GoImports.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
# Sublime3 Plugin that runs goimports on the current file
# Sublime Text 3 Plugin that integrates goimports with your favorite editor
#
# Author: Lukas Zilka ([email protected])
#
import sublime
import sublime_plugin
import subprocess
import io
import os

MY_PATH = os.path.dirname(os.path.realpath(__file__))

def install():
script = [
"GOPATH='%s' go get github.com/bradfitz/goimports" % MY_PATH
]
for ln in script:
p = subprocess.Popen(ln, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if p.wait():
print("Error when installing goimports:")
print(p.stdout.read())
print(p.stderr.read())

if not os.path.exists(os.path.join(MY_PATH, "bin/goimports")):
install()

s = sublime.load_settings("GoImports.sublime-settings")

Expand All @@ -18,7 +34,8 @@ def run(self, edit, saving=False):
content = self.view.substr(selection)

# Shove that content down goimports process's throat.
process = subprocess.Popen([s.get("go_imports_bin_path")], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
process = subprocess.Popen([os.path.join(MY_PATH, "bin/goimports")],
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
process.stdin.write(bytes(content, 'utf8'))
process.stdin.close()
process.wait()
Expand Down
3 changes: 0 additions & 3 deletions GoImports.sublime-settings

This file was deleted.

0 comments on commit faa04f1

Please sign in to comment.