Execute command in the terminal from plugin action

Answered

Hello.

I`m developing a plugin for simplify some routine commands executing by clicking on action.

Now I`m using com.intellij.execution.configurations.GeneralCommandLine class for executing and it`s works fine. But would be great to open the terminal panel in idea and execute command in it.

Is it possible from plugin code?

1
33 comments

If you have `JBTerminalWidget` instance, you can just write command to the input stream:
`widget.getTtyConnector().write("echo foo")`

1

Above code works for me.

Is there a way to determine the current shell type (e.g., PowerShell or Bash)?

I’m encountering a problem when writing a command with multiple lines.

If I use \n to break lines, they are produced in reverse order in PowerShell but appear correct in other shells.
(Powershell)

I was tried to write line by line as well
 

for (line in lines) {
                widget.ttyConnector.write(line)
                widget.ttyConnector.write("\n")
            }

If I use \r\n to break lines, it works for PowerShell but causes issues in other shells.
(Powershell works but with redudant new lines at the end)

I’m trying to detect the shell type to determine the appropriate line break to use.

Do you have any suggestions for resolving this issue?
 

 

0

I am unable to reference TerminalView. What should I do? The version set in IntelliJ Platform is 2.1.0.

0

Please sign in to leave a comment.