Access the most recent command and its response from intelliJ terminal , execute the commands in Terminal

Hi,
I am in my initial phases of writing IntelliJ plugin. My requirement is I want to access the most recent command and its response (if any) from the terminal and also, I need to execute the commands in terminal.
I read that with the help Terminal plugin we can achieve the above.
So I tried to add the terminal dependency in my project like below.
in gradle.properties

platformPlugins = org.jetbrains.plugins.terminal

in build.gradle.kts

 plugins(providers.gradleProperty("platformPlugins").map { it.split(',') })

in plugin.xml

<depends>org.jetbrains.plugins.terminal</depends>

but I am getting

Configuration cache state could not be cached: field `provider` of `org.gradle.internal.serialize.codecs.core.ProviderBackedFileCollectionSpec` bean found in field `element` of `java.util.Collections$SingletonList` bean found in field `elements` of `org.gradle.internal.serialize.codecs.core.ResolutionBackedFileCollectionSpec` bean found in field `__classpathSnapshot__` of `org.jetbrains.kotlin.gradle.tasks.KotlinCompile$ClasspathSnapshotProperties` bean found in field `__classpathSnapshotProperties__` of task `:compileKotlin` of type `org.jetbrains.kotlin.gradle.tasks.KotlinCompile`: error writing value of type 'org.gradle.api.internal.provider.DefaultProvider'
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not find com.jetbrains.plugins:org.jetbrains.plugins.terminal:.
     Required by:
         root project :

Note: I am using intelliJ community edition
if the terminal plugin is not available in community Edition, what is the alternate for this and How to achieve this requirement ?

adding the correct version of the terminal plugin resolves the error.

Could you please provide the steps to add the plugin dependency along with the required version?

Hi,
in order to access org.jetbrains.plugins.terminal.ShellTerminalWidget.executeCommand,
you need to add the terminal plugin dependency

in plugin.xml

<depends>org.jetbrains.plugins.terminal</depends>

in gradle.properties

platformPlugins=org.jetbrains.plugins.terminal:242.20224.237

Note add correct version which is compatible with the intellij version by referring [Terminal Plugin for JetBrains IDEs | JetBrains Marketplace](https://plugins.jetbrains.com/plugin/13123-terminal/versions)

in build.gradle.kts

plugins(providers.gradleProperty("platformPlugins").map { it.split(',') })

clean and build the project

Hi Kiruthika,

Thank you for your response. My primary objective is to execute a terminal command directly within the user’s IDE—specifically, opening the Run or Terminal prompt inside the IDE (not in an external window) and executing the command there. Is this kind of action supported? If so, do you have any sample code that demonstrates how to achieve it?

Thank you,
Tomer

Hello Kiruthika,

I have a similar requirement as you. And stuck in get multi-line responses in terminal because the window may scroll, so ShellTerminalWidget.terminalTextBuffer is hard to use. Do you have a solution for this?

Thanks

Hi shihanmeng,
I don’t have any solution to access the most recent command only. But we can use JBTerminalWidget.getText() to get the entire terminal content.

Thanks.

1 Like

Hi Tomer,
Yes, ShellTerminalWidget.executeCommand will support to execute a terminal command directly within the user’s IDE.
or else we can use jbTerminalWidget.getTtyConnector().write(command) to write the command in terminal and providing additional lineSeparator (like enter) to execute the command, which doesn’t requires to add terminal plugin dependency.
If the terminal is not already opened, we need to get the terminal from ToolWindow and show it using toolwindow.show(), before executing command.