Coder Social home page Coder Social logo

wbond / sublime_terminal Goto Github PK

View Code? Open in Web Editor NEW
596.0 28.0 118.0 76 KB

Launch terminals from the current file or the root project folder

Home Page: https://packagecontrol.io/packages/Terminal

License: MIT License

Shell 33.00% PowerShell 3.07% Python 63.28% Batchfile 0.65%

sublime_terminal's Introduction

Sublime Terminal

Shortcuts and menu entries for opening a terminal at the current file, or the current root project folder in Sublime Text.

Features

  • Opens a terminal in the folder containing the currently edited file
  • Opens a terminal in the project folder containing the currently edited file

Installation

Download Package Control and use the Package Control: Install Package command from the command palette. Using Package Control ensures Terminal will stay up to date automatically.

Usage

  • Open Terminal at File Press ctrl+shift+t on Windows and Linux, or cmd+shift+t on OS X
  • Open Terminal at Project Folder Press ctrl+alt+shift+t on Windows and Linux, or cmd+alt+shift+t on OS X

In addition to the key bindings, terminals can also be opened via the editor context menu and the sidebar context menus.

Package Settings

The default settings can be viewed by accessing the Preferences > Package Settings > Terminal > Settings – Default menu entry. To ensure settings are not lost when the package is upgraded, make sure all edits are saved to Settings – User.

  • terminal
    • The terminal to execute, will default to the OS default if blank. OS X users may enter iTerm.sh to launch iTerm if installed.
    • Default: ""
  • parameters
    • The parameters to pass to the terminal. These parameters will be used if no custom parameters are passed via a key binding.
    • Default: []
  • env
    • The environment variables changeset. Default environment variables used when invoking the terminal are inherited from sublime.
    • The changeset may be used to overwrite/unset environment variables. Use null to indicate that the environment variable should be unset.
    • Default: {}

Examples

Here are some example setups:

Cmder on Windows

{
  // Replace with your own path to cmder.exe
  "terminal": "C:\\Program Files\\cmder_mini\\cmder.exe",
  "parameters": ["/START", "%CWD%"]
}

xterm on GNU/Linux

{
  "terminal": "xterm"
}

gnome-terminal for CJK users on GNU/Linux

{
  "terminal": "gnome-terminal",
  // Unset LD_PRELOAD which may cause problems for sublime with imfix
  "env": {"LD_PRELOAD": null}
}

iTerm on OS X

{
  "terminal": "iTerm.sh"
}

iTerm on OS X with tabs

{
  "terminal": "iTerm.sh",
  "parameters": ["--open-in-tab"]
}

iTerm2 v3 on OS X

{
  "terminal": "iTerm2-v3.sh"
}

Hyper on OS X

{
  "terminal": "hyper.sh"
}
{
  "terminal": "C:/Users/yourusername/AppData/Local/Microsoft/WindowsApps/wt.exe",
  "parameters": ["-d", "."]
}

Custom Parameters

With the parameters argument to the open_terminal and open_terminal_project_folder commands, it is possible to construct custom terminal environments.

The following is an example of passing the parameters -T 'Custom Window Title' to a terminal. Please note that this example is just an example, and is tailored to the XFCE terminal application. Your terminal may use the -T option for some other features or setting. Custom key bindings such as this would be added to the file opened when accessing the Preferences > Key Bindings – User menu entry (the file name varies by operating system).

{
  "keys": ["ctrl+alt+t"],
  "command": "open_terminal",
  "args": {
    "parameters": ["-T", "Custom Window Title"]
  }
}

A parameter may also contain the %CWD% placeholder, which will be substituted with the current working directory the terminal was opened to.

{
  "keys": ["ctrl+alt+t"],
  "command": "open_terminal",
  "args": {
    "parameters": ["-T", "Working in directory %CWD%"]
  }
}

sublime_terminal's People

Contributors

alex7kom avatar beledouxdenis avatar berkandirim avatar calculuswhiz avatar carlosv2 avatar ctf0 avatar dkislov avatar erichdongubler avatar felipenbrito avatar garyking avatar jfcherng avatar kitsguru avatar kristianj avatar luisc009 avatar p3lim avatar peterfyj avatar pinatamostgrim avatar pzgz avatar rogeriopradoj avatar twolfson avatar unowen avatar vitorhsb avatar wbond avatar zertosh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sublime_terminal's Issues

[Bug] OSX Default Terminal Opens Multiple Windows

I like to use the default terminal and no matter how I tinker with this plugin it still opens 2 terminal windows instead of 1 each and every time.

Any ideas on how to fix this? I have not changed any default configuration files.

Thank you

Add shell suport for Git Bash

Since msygit is compatiable with more all OS platform. Thus add the terminal suppot Git Bash too as optional.

For windows I am doing:
Create msygit.bat

start sh --login -i

After that I am User setting for terminal

{ "terminal": "msygit.bat" }

Visual Demonstration

I suggest that you add a couple of screenshots to the project readme so we all can see how it looks/works before having to install it.

A small screencast would be awesome too.

Hide Command prompt on Windows

Open Terminal Here briefly shows a cmd.exe window before launching powershell.exe

This can be easily hidden by passing a startupinfo argument to subprocess.Popen()
Would like me to submit a pull request?

if os.name == 'win':
    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    subprocess.Popen(args, cwd=cwd, startupinfo=startupinfo)
else:
    subprocess.Popen(args, cwd=cwd)

Starting Terminal causes some errors. (Windows 8)

When I use the Terminal(Ctrl+Shift+T) to start a Terminal, and then this happened...I will try to open a powershell, but...

D:\Users\Tony\AppData\Roaming\Sublime Text 2\Packages\Terminal\PS.ps1 : 无法将“D:\Users\Tony\AppData\Roaming\Sublime T
ext 2\Packages\Terminal\PS.ps1”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确
保路径正确,然后再试一次。
所在位置 行:1 字符: 1

  • D:\Users\Tony\AppData\Roaming\SublimeText 2\Packages\Terminal\PS.ps1
  • - CategoryInfo          : ObjectNotFound: (D:\Users\Tony\A...Terminal\PS.ps1:String) [], CommandNotFoundException
    - FullyQualifiedErrorId : CommandNotFoundException
    
    

PS D:\work\cbupe_svn\aliflask>

Open in iTerm2 on the current window

Hello,

I've always iTerm2 opened and I would like that when I click to "Open in terminal here" it just does "cd %path%" in the current window I was. I've got multiple windows on my iTerm2.

Issue with accents

Hi,

I'm a French user of Sublime Text 2. When I try to launch iTerm (or Terminal) with your package, I get the following error:

Terminal: 'ascii' codec can't encode character u'\u0301' in position 30: ordinal not in range(128)

After some research it's due to the fact that there is accents in the folder/file path (when I test with a file without accent in its path it works perfectly). Can you add some patch to figure out this issue?

Thanks.

Using iTerm on Mac instead of the default terminal

I've tried getting the plugin to use iTerm instead of the default terminal on OS X but I can't for the life of me work it out.

So far I've tried…

{ // The command to execute for the terminal, leave blank for the OS default "terminal": "/Applications/iTerm.app" }

As well as a few other attempts without using the path to the apps. Each time I've tried I get the same error, "Terminal: The terminal /Applications/iTerm.app was not found".

Not opening/directory-changing in elementaryOS

It is not working in elementaryOS.

I can fix opening issue with "terminal": "pantheon-terminal", but I can't figure out how to fix the change directory issue.
For now and with empty parameters in setting, terminal opens in /

User Keybindings do not override Defaults on Windows 7

I don't get this behavior from any other package I have installed. No matter what I assign in User keybindings the defaults are still active and not overridden properly. I have to comment out the entries in Defaults to get expected behavior.

[Critical] Terminal opens the different project folder

If I have a directory structure like this: https://cloudup.com/cJXI9jHaDMF

--> Plugins ( Main Directory )
    -- axiscomposer
        - axiscomposer.php
    -- axiscomposer-iconfont
        - axiscomposer-iconfont.php

Now if I will add the two project from above Plugins sub-diectories like this:

-- axiscomposer
    - axiscomposer.php
-- axiscomposer-iconfont
    - axiscomposer-iconfont.php

How to figure out the bug:

  • I will open the file axiscomposer-iconfont.php from second project folder.
  • Now I will use the key ctrl+shift+alt+t to open root project folder in terminal.
  • OOPS Terminal shows the folder of first project instead of the second project.

Remember axiscomposer-iconfont.php is second project file and which using the ctrl+shift+alt+t,
Terminal index read it as of first project file and opens the root folder of first project. This happens if I have the directory and project with names like axiscomposer, axiscomposer-iconfont. IMO this is due to axiscomposer-* names in the directory.

Local variable getting referenced before assignment

The following error pops up after installing the 'sublime-terminal' package in Sublime Text and trying to fire up a terminal:

Terminal: local variable 'default' referenced before assignment

I am on Lubuntu 11.10 which uses the Openbox window manager.

Normal cmd terminal on windows

I'm using this plugin in sublime text 2 on windows.
When I press Ctrl+Shift+T powershell is started. I want to know if it's possible to open the default cmd.exe terminal.
Thanks

Default open_terminal key binding overrides "Reopen Closed File"

I noticed that the keybind shortcut for open_terminal overrides "reopen closed file".

While the terminal plugin is active, the ctrl+shift+T shortcut seems to disappear from the menu, indicating that it is no longer bound to this function.
However, I use the re-open feature a lot, and I am somewhat against overriding a shortcut for a feature that could be considered "core feature".

I could not think of a better shortcut, though.

Umask issue

I'm using Terminal on Ubuntu 13.10 with Sublime Text 3 Stable Build 3059 to launch gnome-terminal. I've been having an issue with my umask which I finally tracked down to this plugin.

If there are no gnome-terminal windows open and I press ctrl+shift+t to launch gnome-terminal, then my umask is set to 000 in that terminal and in all subsequent gnome-terminals until all gnome-terminal windows have been closed.

If there are already gnome-terminal windows open and I pres ctrl+shift+t to launch gnome-terminal, then my umask remains at the default value of 002.

This method of spawning the terminal is the site of the problem:

subprocess.Popen(args, cwd=cwd)

Terminal.app opens in default folder

I'm using OS X Lion & macports & bash.

When I use open terminal in sublime, terminal opens in default "profile" path & NOT current open file path.

PROBLEM: To use bash In Terminal.app I needed to set "Shell opens with:" to "/opt/local/bin/bash -l"

IF i set Terminal.app "Shell opens with:" to "default login shell" -> sublime_terminal opens Terminal.app in current opened file loaction.

Hot to fix it?

"Open Terminal Here" does nothing

I'm on OSX 10.7.4 with ST2.2207

Niether the keyboard shortcuts or the menu option open a terminal.

The command is logged: command: open_terminal {"paths": ["/Users/someperson/somefolder"]}, but nothing happens. Is there anything I can try?

Cygwin

how can i add support to start cygwin mintty terminal ?

Popen causes <defunct>

Popen call without wait() or commuciate() causes processes after terminal quit.

BTW: gnome-terminal does not show anyway when configured as terminal.

How can I run a script in terminal with a shortkey?

Hi, I want to run a script in terminal with a shortkey, but I have no idea how to set the parameters, for example ,when editing a python script, when ctrl+alt+t pressed, the script runs in gnome-terminal, I have rewrote another command class in Terminal.py to achieve that, but I hate the modification, Is there any better way?

ctrl+shift+t shortcut conflict

the ctrl/super+shift+t keyboard shortcut conflicts with the sublime text 2 ctrl+shift+t shortcut which runs the command "reopen_last_file"

Powershell opens with wrong color

Hi wbond,
I've installed sublime_terminal through Package Manager and everytime I try to use it with ctrl+shift+t my new powershell opens with pink background and yellow text, which is horrible to read.
I saw that the Powershell profile is being set by PS.ps1 file, with this configuration:

$pswindow.foregroundcolor = "DarkYellow"
$pswindow.backgroundcolor = "DarkMagenta"

Are those colors really intended to be set in this horrific contrasting duo, or there is really something wrong here?
Thank you.

Terminal: No place to open terminal to

I installed Terminal package, hit Command+Shift+t on a file, and got this error

Terminal: No place to open terminal to

I use Sublime Text 2 on Yosemite 10.10.2

iterm2 bug - not working at all

I have tried adjusting this script for awhile now with now luck:

#!/bin/bash

CD_CMD="cd "\\\"$(pwd)\\\"" && clear"
VERSION=$(sw_vers -productVersion)

if (( $(expr $VERSION '<' 10.7) )); then
    RUNNING=$(osascript<<END
    tell application "System Events"
        count(processes whose name is "iTerm2")
    end tell
END
)
else
    RUNNING=1
fi

if (( $RUNNING )); then
    osascript<<END
    tell application "iTerm2"
        activate
        set term to (make new terminal)
        tell term
            set sess to (launch session "Default Session")
            tell sess
                write text "$CD_CMD"
            end tell
        end tell
    end tell
END
else
    osascript<<END
    tell application "iTerm2"
        activate
        set sess to the first session of the first terminal
        tell sess
            write text "$CD_CMD"
        end tell
    end tell
END
fi

any ideas?

Support for Unicode

If my file path have unicode, it will alert error: Terminal: 'ascii' codec can't encode characters in position 11-13: ordinal not in range(128)

My Solution( for Chinese in Windows):

@@ -102,7 +102,7 @@
        parameters[k] = v.replace('%CWD%', dir)
        args = [TerminalSelector.get()]
        args.extend(parameters)
-       subprocess.Popen(args, cwd=dir)
+      subprocess.Popen(args, cwd=dir.encode("gbk"))
    except (OSError) as (exception):
             print str(exception)

I think it should be encode("utf-8") if you are in Linux.

Run terminal command on opening

When I press Alt+Shift+T to open a terminal, I want to run a terminal command. Mainly I want to run "cd .." to change directory out of my source code to my main project folder where my Makefile is. How can this be done? It looks like editing parameters doesn't work right for this.

iTerm nightly compatibility

I run iTerm nightly (using homebrew cask) but I'd been having issues with Sublime Terminal. I reported it the iTerm developer George Nachman and he cleaned up the iTerm.sh file. His version opens in a new tab of the current terminal by default, which I consider to be the best anyway.

The cleaned up version is available at https://gist.github.com/gnachman/b9ae9cf06c44b5a95edf and it seems reasonable to use it, but I'll hold off for feedback before doing a pull request.

When no text exists in current file, terminal dir is project root.

I'm not sure if this is expected behaviour or not but I thought I'd post an issue to get clarification and for others to be able to quickly check.

To clarify and allow recreation:

  1. Open new file in sub folder of project
  2. Save this empty file with a name
  3. Press ctl+shift+t
  4. terminal opens in project root instead of dir of file.

Comments:

this may be to do with how sublime treats text buffers.

iTerm.sh opening multiple windows

On the first time the Terminal plugin opens iTerm, it opens multiple windows which is kind of annoying.

It looks like it is because of this in iTerm.sh

if (( $(expr $VERSION '<' 10.7) )); then

If I bump the version to 10.8, things work as expected when iTerm has not been opened and after. So I think that is all that needs to be done.

Edit: To be honest, I am not sure why it needs to check the version. Is there some reason this was originally introduced as such?

OS-specific sublime-settings file ignored?

Love this plugin! I'm having an issue with cross-platform syncing, however - I currently am syncing my Packages/User file across Google Drive, so that configuration and plugins are well-integrated in my switches between Linux and Windows installations. With some other plugins (like Sublime itself), one can create settings files of the form:

<name>[ (<platform>)].sublime-settings

When I use the following Terminal.sublime-settings:

{
    "terminal": "C:\\tools\\cygwin\\bin\\mintty.exe"
}

...my terminal changes - I'm able to use Cygwin instead of the default Powershell in Windows 8.1. But when I move this same configuration into Terminal (Windows).sublime-settings, I'm reverted back to defaults. Does this plugin support platform-specific settings?

Not listed in Package Control

"Download Package Control and use the Package Control: Install Package command from the command palette. Using Package Control ensures Terminal will stay up to date automatically. "

Although this is stated, it is not actually listed under the install package command. I've tried on both Windows and Ubuntu.

FiSH doesn't like standard commands

I'm unsure if this could be fixed using the custom params, but, looking at the docs, It doesn't look like it

FiSH (Friendly interactive shell) doesn't like when a command uses &&, and tends to barf on that. The proper way to run multiple commands in FiSH is with semicolons separating commands.

If possible, a way to specify the command run on terminal open would be greatly appreciated. Thanks

Commands

You should add commands to open the Terminal, not everyone like keyboard shortcuts:

[{
    "caption": "Open Terminal in current file location",
    "command": "open_terminal"
}, {
    "caption": "Open Terminal in current project location",
    "command": "open_terminal_project_folder"
}]

Feature request - Ignore the sublime installation path while open powershell

diff --git a/PS.bat b/PS.bat
index e5ade45..8bc017a 100644
--- a/PS.bat
+++ b/PS.bat
@@ -1 +1,4 @@
-start powershell -noexit -ExecutionPolicy RemoteSigned "%APPDATA%\Sublime` Text` 2\Packages\Terminal\PS.ps1"
\ No newline at end of file
+set "cmd=%_PACKAGE_PATH: =` %"
+start powershell -noexit -ExecutionPolicy RemoteSigned "%cmd%\Terminal\PS.ps1"
+
+cls
\ No newline at end of file
diff --git a/Terminal.py b/Terminal.py
index 35d29a1..ff5dc38 100644
--- a/Terminal.py
+++ b/Terminal.py
@@ -106,7 +106,11 @@ class TerminalCommand():
             args = [TerminalSelector.get()]
             args.extend(parameters)
             encoding = locale.getpreferredencoding(do_setlocale=True)
-            subprocess.Popen(args, cwd=dir.encode(encoding))
+^M
+            my_env = os.environ.copy()^M
+            my_env['_PACKAGE_PATH'] = sublime.packages_path().encode('ascii', 'ignore')^M
+^M
+            subprocess.Popen(args, cwd=dir.encode(encoding), env=my_env)^M

         except (OSError) as (exception):
             print str(exception)

PS.ps1 doesn't launch with portable version of Sublime

Using the portable version of Sublime, PS.bat incorrectly references the location of the packages directory with the hard coded value of %APPDATA%...

With sublime being a portable edition I can't reliably hard code a different path as drive letters change, or in my instance, the Dropbox folder may reside in different physical directories.

Remove Default.sublime-commands

Please don't clutter up peoples Command Palette with rarely used commands. These are easily accessible in the Preferences->Package Settings like every other plugin' settings.

Problem with Fish shell on OS X

Because it tries to run "cd /asd/qwe && clear", and && apparently is bash syntax and not supported in the excellent fish shell, can you please make this run as two separate commands instead of one liner.

PYTHONPATH environment variable disappears in Windows' terminals

When I try launching a new terminal (cmd or powershell) in Windows 7, the terminal that pops up doesn't have the PYTHONPATH environment variable set, which means some of the imports in my python projects don't work. My PYTHONPATH variable was setup like described in http://stackoverflow.com/a/4855685/1030774

I can get around it by doing a batch file hack for cmd, but I'm wondering whether there is a way to bypass it somehow:

C:\path\to\folder\ccmd.bat

@echo off
call :cdtmp > "C:\path\to\folder\cdtmp.bat"
start "clean shell" /i "%windir%\explorer.exe" "C:\path\to\folder\cdtmp.bat"
exit
goto:eof

:cdtmp
echo cmd /k "cd %CD%"
goto:eof

{Sublime Packages}\User\Terminal.sublime-settings

{
    "terminal": "C:\\path\\to\\folder\\ccmd.bat"
}

Disable open_terminal shortcut

How can I disable super+shift+t as the open_terminal shortcut? Because I need it for opening my most recently closed files.

Non-default shell "Console2" renders the "Open terminal here..." useless

If left to use the default terminal, in my case Powershell, the plugin functions as described. Hotkeys, right-click menu options all work perfectly.
However after changing the terminal to Console2 only the Ctrl+Shift+T hotkeys function, showing the terminal opening in its folder. The right-click menu in both the sidebar and the main editing window result in an error dialog "Terminal: The terminal console2 was not found here."

If I change the terminal to use "cmd" everything again functions as normal.
In all situations I can use these 3 different terminals properly no matter where on the system I start them. They are all in the PATH and all behave as would be expected.

Support opening multiple terminal apps

I don't know if there is a way to do this already (i couldn't see one), but for half my projects I need to the windows power shell open and for the other half I need Cygwin's mintty. Can it be possible to create two different commands for each?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.