Sublime Forum

Connect external terminal to Sublime

#1

I have written a small plugin that I would like to share. The plugin connects an external terminal to Sublime. It works on Linux only.

I use it for two things:

  • It can run build commands in the external terminal rather than inside sublime.
  • Per default, the terminal runs bash, but it can run any program (for example a python shell). The plugin can run code snippets from the text editor by selecting text and pressing a shortcut. The corresponding command is “send” and the default shortcut is “ctrl+d”.

I have tried several built-in Sublime terminals, but for me nothing beats having my good old system terminal open on my secondary monitor and Sublime on the primary. Maybe this is useful for others as well.

I put the code on github: https://github.com/tobiasrenkin/sublime-console. Feedback is very welcome.

Cheers,
Tobias

1 Like

#2

I managed to configure Sublime Text 2 for C++ and I can now compile my code (using the MinGW compiler).

Unfortunately, the Sublime Text console can’t support any kind of input for C++.

I want to open my compiled program in an external console (Window’s terminal for instance). I tried to use “call” or “cmd” but couldn’t make it work. (it still opens the file in the console)

Here’s my build configuration:

{
"cmd": ["C:\\MinGW\\bin\\mingw32-g++.exe", "-Wall", "-time", "$file", "-o", "$file_base_name"],
"cmd": ["call", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"working_dir": "${project_path:${folder}}",
"selector": "source.c",
"shell": true,
"encoding": "latin1"
}

The text editor is pretty good, however, one thing I don’t like about it is that build/execute results are shown in its native console rather than system default shell-like gnome-terminal. Basically, at first, I have executed this on remote onboarding software and related things.

This problem can be easily solved by creating a new build file and adding following to it:

{
"cmd": [“gnome-terminal -e “python $file””],
"shell": true
}

Note that using this this method, gnome-terminal will be closed when the process is terminated. If you like a Geany like approach where terminal stays open for reviewing results, we can do the same using Geany’s run script.

Create a new bash script with following in it:

#!/bin/sh

python $1

echo "

------------------
(program exited with code: $?)"

echo "Press return to continue"
dummy_var=""
read dummy_var

Now create new sublime build file with following in it:

{
"cmd": [“gnome-terminal -e “/your/run/script.sh $file””],
"shell": true
}

Replace path of your own run script in above command. Make sure your script has executable permissions.

Lastly, Sublime Text’s build console will still pop up at the bottom. To disable it for build results, add this to your user settings file:

"show_panel_on_build": false

The little hiccup I didn’t write the full path to the script properly, the following worked for me. Read the link above and then have a look at my syntax. Doing something similar shoudl work for you!

{
"cmd": ["sh /Users/InNov8/Dropbox/Code/^sublimeRunFile.sh \"$file\""],
"shell": true
}

Hope this article helps you properly.

0 Likes