Created
December 26, 2012 16:27
-
-
Save dkandalov/4381246 to your computer and use it in GitHub Desktop.
intellij-eval plugin to compile and run single ".c" file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/sh | |
FILE_NAME=$1 | |
FILE_PATH=$2 | |
gcc -o $FILE_NAME $FILE_PATH/$FILE_NAME.c && ./$FILE_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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