• Stars
    star
    1,382
  • Rank 34,014 (Top 0.7 %)
  • Language
    Python
  • License
    MIT License
  • Created over 6 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bring a real terminal to Sublime Text

Bring a real terminal to Sublime Text

The first cross platform terminal for Sublime Text.

Unix shell Cmd.exe
Terminal in panel Support showing images

This package is heavily inspired by TerminalView. Compare with TerminalView, this has

  • Windows support
  • continuous history
  • easily customizable themes (see Terminus Utilities)
  • unicode support
  • 256 colors support
  • better xterm support
  • terminal panel
  • imgcat support (PS: it also works on Linux / WSL)

Installation

Package Control.

Getting started

Shell configurations

Terminus comes with several shell configurations. The settings file should be quite self explanatory.

User Key Bindings

You may find these key bindings useful. To edit, run Preferences: Terminus Key Bindings. Check the details for the arguments of terminus_open below.

  • toggle terminal panel
[
    { 
        "keys": ["alt+`"], "command": "toggle_terminus_panel"
    }
]
  • open a terminal view at current file directory
[
    { 
        "keys": ["ctrl+alt+t"], "command": "terminus_open", "args": {
            "cwd": "${file_path:${folder}}"
        }
    }
]

or by passing a custom cmd, say ipython

[
    { 
        "keys": ["ctrl+alt+t"], "command": "terminus_open", "args": {
            "cmd": "ipython",
            "cwd": "${file_path:${folder}}"
        }
    }
]
  • open terminal in a split view by using Origami's carry_file_to_pane
[
    {
        "keys": ["ctrl+alt+t"],
        "command": "terminus_open",
        "args": {
            "post_window_hooks": [
                ["carry_file_to_pane", {"direction": "down"}]
            ]
        }
    }
]
  • ctrl-w to close terminal

Following keybinding can be considered if one wants to use ctrl+w to close terminals.

{ 
    "keys": ["ctrl+w"], "command": "terminus_close", "context": [{ "key": "terminus_view"}]
}

User Commands in Palette

  • run Preferences: Terminus Command Palette. Check the details for the arguments of terminus_open below
[
    {
        "caption": "Terminus: Open Default Shell at Current Location",
        "command": "terminus_open",
        "args"   : {
            "cwd": "${file_path:${folder}}"
        }
    }
]

or by passing custom cmd, say ipython

[
    {
        "caption": "Terminus: Open iPython",
        "command": "terminus_open",
        "args"   : {
            "cmd": "ipython",
            "cwd": "${file_path:${folder}}",
            "title": "iPython"
        }
    }
]
  • open terminal in a split tab by using Origami's carry_file_to_pane
[
    {
        "caption": "Terminus: Open Default Shell in Split Tab",
        "command": "terminus_open",
        "args": {
            "post_window_hooks": [
                ["carry_file_to_pane", {"direction": "down"}]
            ]
        }
    }
]

Terminus Build System

It is possible to use Terminus as a build system. The target terminus_exec is a drop in replacement of the default target exec. It takes exact same arguments as terminus_open except that their default values are set differently.

terminus_cancel_build is used to cancel the build when user runs cancel_build triggered by ctrl+c (macOS) or ctrl+break (Windows / Linux).

The following is an example of build system define in project settings that run a python script

{
    "build_systems":
    [
        {
            "name": "Hello World",
            "target": "terminus_exec",
            "cancel": "terminus_cancel_build",
            "cmd": [
                "python", "helloworld.py"
            ],
            "working_dir": "$folder"
        }
    ]
}

The same Hello World example could be specified via a .sublime-build file.

{
    "target": "terminus_exec",
    "cancel": "terminus_cancel_build",
    "cmd": [
        "python", "helloworld.py"
    ],
    "working_dir": "$folder"
}

Instead of cmd, user could also specify shell_cmd. In macOS and linux, a bash shell will be invoked; and in Windows, cmd.exe will be invoked.

{
    "target": "terminus_exec",
    "cancel": "terminus_cancel_build",
    "shell_cmd": "python helloworld.py",
    // to directly invoke bash command
    // "shell_cmd": "echo helloworld",
    "working_dir": "$folder"
}

Alt-Left/Right to move between words (Unix)

  • Bash: add the following in .bash_profile or .bashrc

    if [ "$TERM_PROGRAM" == "Terminus-Sublime" ]; then
        bind '"\e[1;3C": forward-word'
        bind '"\e[1;3D": backward-word'
    fi
  • Zsh: add the following in .zshrc

    if [ "$TERM_PROGRAM" = "Terminus-Sublime" ]; then
        bindkey "\e[1;3C" forward-word
        bindkey "\e[1;3D" backward-word
    fi

Some programs, such as julia, do not recognize the standard keycodes for alt+left and alt+right. You could bind them to alt+b and alt+f respectively

[
    { "keys": ["alt+left"], "command": "terminus_keypress", "args": {"key": "b", "alt": true}, "context": [{"key": "terminus_view"}] },
    { "keys": ["alt+right"], "command": "terminus_keypress", "args": {"key": "f", "alt": true}, "context": [{"key": "terminus_view"}] }
]

Terminus API

  • A terminal could be opened using the command terminus_open with
window.run_command(
    "terminus_open", {
        "config_name": None,     # the shell config name, use `None` for the default config
        "cmd": None,             # the cmd to execute
        "shell_cmd": None,       # a script to execute in a shell
                                 # bash on Unix and cmd.exe on Windows
        "cwd": None,             # the working directory
        "working_dir": None,     # alias of "cwd"
        "env": {},               # extra environmental variables
        "title": None,           # title of the view, let terminal configures it if leave empty
        "panel_name": None,      # the name of the panel if terminal should be opened in panel
        "focus": True,           # focus to the panel
        "tag": None,             # a tag to identify the terminal
        "file_regex": None       # the `file_regex` pattern in sublime build system
                                 # see https://www.sublimetext.com/docs/3/build_systems.html
        "line_regex": None       # the `file_regex` pattern in sublime build system
        "pre_window_hooks": [],  # a list of window hooks before opening terminal
        "post_window_hooks": [], # a list of window hooks after opening terminal
        "post_view_hooks": [],   # a list of view hooks after opening terminal
        "auto_close": True,      # auto close terminal if process exits successfully
        "cancellable": False,    # allow `cancel_build` command to terminate process, only relevent to panels
        "timeit": False          # display elapsed time when the process terminates
    }
)

The fields cmd and cwd understand Sublime Text build system variables.

  • the setting view.settings().get("terminus_view.tag") can be used to identify the terminal and

  • keybind can be binded with specific tagged terminal

    {
        "keys": ["ctrl+alt+w"], "command": "terminus_close", "context": [
            { "key": "terminus_view.tag", "operator": "equal", "operand": "YOUR_TAG"}
        ]
    }
  • text can be sent to the terminal with
window.run_command(
    "terminus_send_string", 
    {
        "string": "ls\n",
        "tag": "<YOUR_TAG>"        # ignore this or set it to None to send text to the first terminal found
        "visible_only": False      # send to visible terminal only, default is `False`. Only relevent when `tag` is None
    }
)

If tag is not provided or is None, the text will be sent to the first terminal found in the current window.

FAQ

Memory issue

It is known that Terminus sometimes consumes a lot of memory after extensive use. It is because Sublime Text keeps an infinite undo stack. There is virtually no fix unless upstream provides an API to work with the undo stack. Meanwhile, users could execute Terminus: Reset to release the memory.

This issue has been fixed in Sublime Text >= 4114 and Terminus v0.3.20.

Color issue when maximizing and minimizing terminal

It is known that the color of the scrollback history will be lost when a terminal is maximized or minimized from or to the panel. There is no fix for this issue.

Terminal panel background issue

If you are using DA UI and your terminal panel has weird background color, try playing with the setting panel_background_color or panel_text_output_background_color in DA UI: Theme Settings.

{
    "panel_background_color": "$background_color"
}

Or, to keep the Find and Replace panels unchanged:

"panel_text_output_background_color": "$background_color"

Cmd.exe rendering issue in panel

Due to a upstream bug (may winpty or cmd.exe?), there may be arbitrary empty lines inserted between prompts if the panel is too short. It seems that cmder and powershell are not affected by this bug.

Acknowledgments

This package won't be possible without pyte, pywinpty and ptyprocess.

More Repositories

1

radian

A 21 century R console
Python
1,976
star
2

AlignTab

An alignment plugin for Sublime Text using regular expression
Python
626
star
3

ProjectManager

Project Manager for Sublime Text
Python
323
star
4

SendCode

Send code and text to macOS and Linux Terminals, iTerm, ConEmu, Cmder, Tmux, Terminus; R (RStudio), Julia, IPython.
Python
204
star
5

R-Box

R package for Sublime Text 3
Python
172
star
6

collections

High-performance container datatypes for R
R
102
star
7

remote-atom

rmate for atom
CoffeeScript
85
star
8

LaTeXYZ

Better LaTeX experience with Sublime Text
Python
74
star
9

AutoWrap

Auto (Hard) Wrap for Sublime Text 2/3
Python
63
star
10

arrangements

Fast Generators and Iterators of Permutations, Combinations and Partitions
R
52
star
11

rchitect

Interoperate R with Python
Python
51
star
12

LaTeXBox

A lightweight but deprecated LaTeX Plugin for Sublime Text 3
Python
46
star
13

Whitespace

Remove Trailing Whitespace for Sublime Text
Python
41
star
14

AutomaticPackageReloader

Automatically reload submodules while developing a Sublime Text package.
Python
37
star
15

shiny-cloudrun-demo

Running Shiny app on Google Cloud Run
R
34
star
16

UnitTesting-example

A getting started example for UnitTesting
Python
32
star
17

dotfiles

some of my dotfiles
Python
30
star
18

ChangeList

DEPRECATED: The missing Change List for Sublime Text 2/3 - History List, Last Edit ...
Python
30
star
19

SyntaxManager

Applying settings to a given syntax/extension
Python
29
star
20

homebrew-r

Homebrew formulas for R and related tools
Ruby
25
star
21

UnicodeCompletion

Insert Unicode LaTeX δ and Emoji 🍻 to Sublime Text
Python
24
star
22

LaTeXTab

Excel/CSV to LaTeX Table
Python
18
star
23

SendTextPlus

SendTextPlus is deprecated in favour of https://github.com/randy3k/SendCode
Python
17
star
24

otp

One Time Password Generation and Verification
R
16
star
25

retry

Repeated Evaluation
R
15
star
26

rpy2

Deprecated: use the official mirror: https://github.com/rpy2/rpy2
Python
15
star
27

xptr

Manipulating External Pointer
R
13
star
28

GitStatusBar

A more compact Git StatusBar
Python
13
star
29

rango

Calling R from Go and a better cli for the R console (WIP, nothing is working now)
Go
12
star
30

osascript

some useful apple scripts
AppleScript
9
star
31

iterpc

iterpc: deprecated in favour of https://github.com/randy3k/arrangements
R
9
star
32

sublime-default

Sublime Text 3 Default Package - This rpeo is outdated, check https://github.com/twolfson/sublime-files
Python
9
star
33

OpenHere

Open Finder, Terminal and iTerm in Sublime Text
AppleScript
5
star
34

GitHubChecks

Show GitHub checks result in Sublime Text
Python
5
star
35

sess

R
3
star
36

closure

Tools to create and manipulate closures
R
3
star
37

LSP-julia

Julia config for Sublime Text LSP
Python
3
star
38

netlify-deploystatus

JavaScript
3
star
39

random-scripts

some random scripts
Python
2
star
40

R-Extended

Improved R syntax files for Sublime Text
JavaScript
2
star
41

Keypress

Simulate Keypress in Sublime Text
Python
2
star
42

shiny-appengine-demo

Running Shiny app on Google App Engine
R
1
star
43

lineedit

lineedit: a readline library based on prompt_toolkit which supports multiple modes
Python
1
star
44

gh-actions

Shell
1
star
45

juliatalk

Jupyter Notebook
1
star
46

workbench

Bootstrapping my workbench on unix machines
Shell
1
star
47

randylai.info

source of randylai.info
HTML
1
star
48

UnitTesting-docker

Go to https://github.com/SublimeText/UnitTesting/tree/master/docker
Shell
1
star
49

ustring

Tools For Unicode Strings
R
1
star
50

RSpace

A Cocoa GUI for R on OSX
Objective-C
1
star
51

submit

A webapp for submitting project
HTML
1
star