Sublime Forum

Terminal Plugin

#1

This is a simple plugin to allow for opening a terminal at the current file, or the current project folder. Terminals can be opened via key command or context menus. It works on Windows, OS X and Linux.

Full documentation including installation instructions, settings, key bindings and changelog is available at wbond.net/sublime_packages/terminal.

[size=150]Updates[/size]

  • 2011-11-28 - version 1.3.1 released

  • 2011-11-05 - version 1.3.0 released

  • 2011-08-30 - version 1.2.0 released

1 Like

#2

Another killer plugin. Thanks wbond!

0 Likes

#3

Hmm, I just had a thought that this could be useful to quickly launching SASS or LiveReload. Is it possible to set a shortcut or right click menu option that passes the terminal some arguments?

0 Likes

#4

I should be able to make the command accept an optional argument that would be passed to the terminal. Then you could create a menu entry or keyboard shortcut that would call the open terminal command with whatever parameters you wanted.

0 Likes

#5

Yeah that would be ideal. Thanks.

0 Likes

#6

That would be awesome. Thanks!

0 Likes

#7

I use Console2 as my terminal and to pass it a directory to open at, you need this template:

"C:\Program Files\Console2\Console.exe" -d "%1"

You can also pass it a tab argument:

"C:\Program Files\Console2\Console.exe" -t "Git Bash" -d "%1"

This would open Console using the tab settings named ā€œGit Bashā€. That is, it would open a new Git Bash prompt. Would be good to be able to configure the optional argument to accommodate these settings. For convenience, Iā€™ve copied in the content of the help docs in regard to command line options:

[code]Command line parameters
Console supports these command line parameters:

-c
Specifies a configuration file.

-w
Sets main window title. This option will override all other main window title settings (e.g. ā€˜use tab titlesā€™ setting)

-t
Specifies a startup tab. Tab must be defined in Console settings.

-d
Specifies a startup directory. If you want to parametrize startup dirs, you need to specify startup directory parameter as ā€œ%1ā€\ (backslash is outside of the double quotes)

-r
Specifies a startup shell command.

-ts
Specifies sleep time between starting next tab if multiple -tā€™s are specified.

Note: -t option is not used to set tabā€™s title. It specifies one of the names of the tabs defined in Console settings.

Note: If you specify multiple -t options, you can specify multiple -d and -r options as well. In that case, each -t, -d and -r option will be grouped together. If there is no corresponding -d option for a -t option, the initial directory from that tabā€™s settings will be used. For example:

Console.exe -t bash -d C:\WINDOWS -r ā€œls -alā€ -t cmd -d D:\ -t ncftp

Will start ā€˜bashā€™ tab in C:\WINDOWS, running ā€œls -alā€ command in it and ā€˜cmdā€™ tab in D:. ā€˜ncftpā€™ tab will be started in the initial directory specified in its settings.

Note: Some shells need an additional switch in the startup command string. E.g. when using cmd.exe, you must put /k at the beginning of your command string:

Console.exe -t cmd -r ā€œ/k dir /bā€

Note: -ts option can be useful if you want to start multiple instances of a tab, and tabā€™s shell needs write access to some files during initialization Using -ts option, you can specify time to sleep between starting the next tab, giving each shell enough time to initialize itself.
[/code]

So, riffing on the Sass and Livereload stuff, we could open up two tabs and run shell commands to start up the Sass watcher in one and Livereload in another, all from one command. That would be pretty sweet.

0 Likes

#8

I just tested out Console 2 and it worked as expected just setting the exe path. What the plugin does is launch the exe with the CWD set to the directory that contains the file or folder you were editing or selected.

For passing arguments to the terminal, youā€™d either have to write a batch script, or wait until I add support for passing parameters. The way it is implemented with the subprocess module right now, the program path needs to be separate from any arguments.

0 Likes

#9

Version 1.1.0 now supports default parameters to the terminal application and also has a parameters arg for the open_terminal and open_terminal_project_folder commands. wbond.net/sublime_packages/terminal has documentation and an example.

0 Likes

#10

Iā€™ve changed my terminal to:

"terminal": "C:\\Windows\\system32\\cmd.exe",

The terminal window loads, however it takes nearly a minute for a prompt to appear.

0 Likes

#11

[quote=ā€œatomiā€]Iā€™ve changed my terminal to:

"terminal": "C:\\Windows\\system32\\cmd.exe",

The terminal window loads, however it takes nearly a minute for a prompt to appear.[/quote]

This bug has been fixed in version 1.1.1.

0 Likes

#12

Weird, that definitely didnā€™t work for me. I upgraded to 1.1.1 and have it working now, though. If anyone else is using Console2 on Windows, hereā€™s the incantation I used in my Terminal users settings:

{ // The command to execute for the terminal, leave blank for the OS default "terminal": "C:\\Dropbox\\Software\\Console2\\Console.exe", "parameters": "-d", "."] }

Works a treat now! Thanks Will. :smile:

0 Likes

#13

I canā€™t get custom parameters to work on windows :stuck_out_tongue:

This open default CMD terminal in the right place but doesnā€™t pass the parameters.

"keys": "ctrl+alt+shift+m"],
	"command": "open_terminal_project_folder",
	"args": {
		"parameters": "middleman server --livereload"]
	}
0 Likes

#14

[quote=ā€œfirefusionā€]I canā€™t get custom parameters to work on windows :stuck_out_tongue:

This open default CMD terminal in the right place but doesnā€™t pass the parameters.

"keys": "ctrl+alt+shift+m"], "command": "open_terminal_project_folder", "args": { "parameters": "middleman server --livereload"] } [/quote]

There should be one parameter per string in the parameters list:

"keys": "ctrl+alt+shift+m"],
	"command": "open_terminal_project_folder",
	"args": {
		"parameters": "middleman", "server", "--livereload"]
	}
0 Likes

#15

Still no joy. It doesnā€™t even pass one parameter if it reduce it to that.

Iā€™ve tried it with cmd, powershell and running sublime in admin mode.

Windows 64bit.

0 Likes

#16

[quote=ā€œfirefusionā€]Still no joy. It doesnā€™t even pass one parameter if it reduce it to that.

Iā€™ve tried it with cmd, powershell and running sublime in admin mode.

Windows 64bit.[/quote]

I just took a step back and I donā€™t think powershell or cmd understand the arguments middleman, server or --livereload. Are you trying to run a program in powershell called middleman? Sublime Terminal doesnā€™t currently do that, it simply opens a terminal for you to interact with.

0 Likes

#17

Hmm. I think I see. But if I type ā€œmiddleman server --livereloadā€ into the terminal window opened from the keyboard command middleman runs fine. So I thought this was a way of passing its first command.

Btw for anyone who wants to know Middleman is a great ruby gem for webdevelopment middlemanapp.com/

0 Likes

#18

This is a nice plugin, and one I had wanted to implement for a while. We would like it if you could fork your plugin over to the SublimeText org on GitHub. Follow the link to get instructions for requesting membership to the org:
github.com/SublimeText

0 Likes

#19

[quote=ā€œwilli297ā€]This is a nice plugin, and one I had wanted to implement for a while. We would like it if you could fork your plugin over to the SublimeText org on GitHub. Follow the link to get instructions for requesting membership to the org:
github.com/SublimeText[/quote]

You can fork it from github.com/wbond/sublime_terminal.

0 Likes

#20

Another great plugin - good stuff! However, Iā€™m seeing some interesting behaviorā€¦ Iā€™m not sure if Iā€™ve got something conflicting or not. I setup my user settings for Terminal to work with sh.exe (Git Bash on Win7) as follows:

{ "terminal": "C:/Program Files (x86)/Git/bin/sh.exe", "parameters": "--login", "-i"] }
Nothing special there, just the path to sh.exe and the params needed. Now this works just fine if I hit Ctrl-Shift-T. However, if I hit the keybind while editing a PHP or HTML file, it doesnā€™t do anything (and nothing appears in the console). All other file types appear to be working fine.

If I take a copy of the default keybinds and add them to my user keybinds, then everything works fine. Weird! :smile:

Let me know if thereā€™s something I can do to help you debug this on my end. In the meantime Iā€™ll just keep a copy of the keybinds in my user keybinds file.

Thanks!

0 Likes