For example, this action executes “echo Hello” command in a new terminal tab in the Terminal tool window:
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.terminal.ui.TerminalWidget
import org.jetbrains.plugins.terminal.TerminalToolWindowManager
class ExecuteEchoHelloInTerminalAction : DumbAwareAction("Execute 'echo Hello' in a new terminal tab") {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
val widget: TerminalWidget = TerminalToolWindowManager.getInstance(project).createShellWidget(null, null, true, true)
widget.sendCommandToExecute("echo Hello")
}
}