Skip to content

Instantly share code, notes, and snippets.

@dkandalov
Created December 26, 2012 16:27
Show Gist options
  • Save dkandalov/4381246 to your computer and use it in GitHub Desktop.
Save dkandalov/4381246 to your computer and use it in GitHub Desktop.
intellij-eval plugin to compile and run single ".c" file
#/bin/sh
FILE_NAME=$1
FILE_PATH=$2
gcc -o $FILE_NAME $FILE_PATH/$FILE_NAME.c && ./$FILE_NAME
import com.intellij.notification.*
import static ru.intellijeval.EvalComponent.*
import static ru.intellijeval.PluginUtil.*
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.fileEditor.FileDocumentManager
static show(String htmlBody, String title = "", notificationType = NotificationType.INFORMATION) {
((Notifications) NotificationsManager.notificationsManager).notify(new Notification("", title, htmlBody, notificationType))
}
registerAction("compile-c", "alt R", {
VirtualFile file = FileEditorManagerEx.getInstance(event.project).currentFile
if (file.extension != "c") return
def docManager = FileDocumentManager.instance
def document = docManager.getDocument(file)
if (document != null) docManager.saveDocument(document)
String pathToPlugin = pluginToPathMap().get("compile-c")
def command = "./compile-and-run.sh ${file.nameWithoutExtension} ${file.parent.path}"
def process = Runtime.runtime.exec(command, new String[0], new File(pathToPlugin))
def stdout = process.inputStream.readLines()
def stderr = process.errorStream.readLines()
String text = ""
if (!stderr.empty) text += "> $command\n" + stderr.join("\n") + "\n\n-------------\n\n"
text += "> $command\n" + stdout.join("\n")
showInConsole(text, event.project)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment