tl

package module
v0.0.0-...-a3c73fb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 4 Imported by: 0

README

tl

A Go package and CLI tool for launching a command in a new terminal window, tab, or pane. Provides a single, uniform API across major multiplexers and terminal emulators.

Supported environments

Terminal Window Tab Pane (V/H) Detection
iTerm2 $TERM_PROGRAM=iTerm.app
Kitty $KITTY_WINDOW_ID
Terminal.app ↓ tab $TERM_PROGRAM=Apple_Terminal
tmux $TMUX
WezTerm $WEZTERM_PANE / $TERM_PROGRAM=WezTerm
Windows Terminal $WT_SESSION
Zellij ↓ tab $ZELLIJ_SESSION_NAME

↓ = falls back gracefully to the next supported target.

CLI: tl

tl <subcommand> [flags] -- <command> [args...]

Subcommands:
  tab      Open a new tab (default)
  vsplit   Open a vertical split pane
  hsplit   Open a horizontal split pane
  window   Open a new window

Flags:
  --dir    working directory
  --name   title for the new window/tab/pane
Examples
# Open vim in a new tab (auto-detects terminal)
tl -- vim .

# Open test output in a vertical split
tl vsplit -- go test -v ./...

# Tail a log in a horizontal pane in a specific directory
tl hsplit --dir /var/log --name "app logs" -- tail -f app.log

# Generate shell completions
tl completion bash
Install
go install github.com/pgavlin/tl/cmd/tl@latest

Package API

import "github.com/pgavlin/tl"

// Auto-detect terminal, open a new tab.
err := tl.Launch([]string{"vim", "."}, tl.Options{
    Target: tl.TargetTab,
})

// Open a vertical split with a working directory and title.
err = tl.Launch([]string{"htop"}, tl.Options{
    Target: tl.TargetPaneVertical,
    Dir:    "/var/log",
    Name:   "system monitor",
})
Options
type Options struct {
    Target Target // TargetWindow | TargetTab | TargetPaneVertical | TargetPaneHorizontal
    Dir    string // working directory (empty = inherit)
    Name   string // title hint (best-effort; not all terminals support it)
}

Fallback behaviour

When the requested target is not supported by the detected terminal, the library automatically tries the next best option rather than returning an error:

TargetPaneVertical   → TargetPaneHorizontal → TargetTab → TargetWindow
TargetPaneHorizontal → TargetPaneVertical   → TargetTab → TargetWindow
TargetTab            → TargetWindow
TargetWindow         → (error if nothing works)

Terminal-specific notes

Kitty

Requires allow_remote_control yes in kitty.conf.

Zellij

Tab-level launches write a temporary KDL layout file consumed by zellij action new-tab --layout. The file is deleted after the command runs. Zellij has no OS window concept; TargetWindow falls back to TargetTab.

macOS Terminal.app

Tab creation uses a System Events keystroke (Cmd+T) because Terminal.app has no AppleScript verb for "new tab". Terminal.app must be in the foreground when the command runs. Pane splitting is not supported.

iTerm2

Uses AppleScript (osascript). No extra configuration needed. For richer automation, consider using the iTerm2 Python API directly.

License

MIT

Documentation

Overview

Package tl provides a unified API for opening a command in a new terminal window, tab, or pane across multiple terminal emulators and multiplexers.

Quick start:

err := tl.Launch([]string{"vim", "."}, tl.Options{
    Target: tl.TargetTab,
})

The terminal is auto-detected from environment variables. If the requested target type (e.g. a pane split) is not supported, the library falls back gracefully to the next best option.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Launch

func Launch(cmd []string, opts Options) error

Launch auto-detects the running terminal and opens cmd with automatic fallback if the exact target type is unsupported.

Types

type Options

type Options struct {
	// Target is where to open the command. Defaults to TargetTab.
	Target Target

	// Dir is the working directory for the new pane/tab/window.
	// An empty string inherits the terminal's default (usually the current dir).
	Dir string

	// Name is a title hint for the new window, tab, or pane.
	// Not all terminals honour this; it is applied on a best-effort basis.
	Name string
}

Options configures how a command is launched.

type Target

type Target int

Target describes where the new command should be opened.

const (
	// TargetWindow opens a new top-level OS window.
	TargetWindow Target = iota
	// TargetTab opens a new tab inside the current window.
	TargetTab
	// TargetPaneVertical opens a vertical split (new pane to the right).
	TargetPaneVertical
	// TargetPaneHorizontal opens a horizontal split (new pane below).
	TargetPaneHorizontal
)

func ParseTarget

func ParseTarget(s string) (Target, error)

ParseTarget converts a string to a Target. Accepted values: "window" / "w", "tab" / "t", "pane-v" / "vsplit", "pane-h" / "hsplit".

func (Target) String

func (t Target) String() string

Directories

Path Synopsis
cmd
tl command
tl launches a command in a new terminal window, tab, or pane.
tl launches a command in a new terminal window, tab, or pane.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL