惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
J
Java Code Geeks
V
V2EX
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
B
Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
月光博客
月光博客
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
腾讯CDC
美团技术团队
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
N
Netflix TechBlog - Medium
C
Check Point Blog
Recent Announcements
Recent Announcements
博客园 - Franky
博客园 - 叶小钗
T
Tailwind CSS Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Build a reusable Terminator layout with pre-loaded comman...
Isaac · 2026-04-30 · via DEV Community

Isaac

If you regularly work across multiple servers, environments, or services, you probably know this dance: open a terminal, split it three ways, type the same SSH command in one pane, the same tail -f in another, and a ping in the third. Every time. For every host.

This post walks through building a single shell script that opens
Terminator with a custom layout — three panes, each with its own title and a list of commands pre-loaded into shell history, ready to fire with a single up arrow.

#!/bin/bash
#
# multi-pane.sh — Abre Terminator con un layout de 3 paneles personalizables,
# cada uno con su propio título y comandos precargados en el historial
# (listos para ejecutar con flecha arriba).
#
# Uso: ./multi-pane.sh <argumento>
#
# El argumento se sustituye en los títulos y comandos de cada panel.
# Útil para flujos donde alternás entre múltiples hosts/entornos.
#

set -euo pipefail

ARG=${1:?Uso: $(basename "$0") <argumento>}

CONFIG="$HOME/.config/terminator/config"
RC_LEFT=/tmp/multi-pane-rc-left
RC_TOP_RIGHT=/tmp/multi-pane-rc-top-right
RC_BOTTOM_RIGHT=/tmp/multi-pane-rc-bottom-right

# ---------------------------------------------------------------------------
# gen_rc: genera un rcfile temporal que será cargado por bash con --rcfile.
# Hace dos cosas:
#   1) Sourcea ~/.bashrc para mantener el entorno habitual del usuario.
#   2) Inyecta cada comando recibido como argumento en el historial mediante
#      `history -s`, sin ejecutarlo. El último argumento queda más cerca del
#      prompt (1 sola flecha arriba para acceder).
# ---------------------------------------------------------------------------
gen_rc() {
    local rcfile=$1
    shift
    {
        echo '[ -f "$HOME/.bashrc" ] && source "$HOME/.bashrc"'
        for cmd in "$@"; do
            echo "history -s \"$cmd\""
        done
    } > "$rcfile"
}

# Comandos por panel — personalizá según tu flujo.
# El último argumento es el primero al que accedés con flecha arriba.
gen_rc "$RC_LEFT" \
    "echo 'segundo comando'" \
    "echo 'primer comando (flecha arriba lo trae)'"

gen_rc "$RC_TOP_RIGHT" \
    "ls -la" \
    "pwd"

gen_rc "$RC_BOTTOM_RIGHT" \
    "date"

# ---------------------------------------------------------------------------
# Inyección del layout en el config de Terminator.
#
# Se inserta directamente en ~/.config/terminator/config en lugar de usar
# un archivo separado con `-g`. ¿Por qué? Porque `-g` reemplaza la config
# completa, perdiendo fuente, colores y atajos personales del usuario.
# Inyectando en el config real, todo se hereda automáticamente.
# ---------------------------------------------------------------------------

mkdir -p "$(dirname "$CONFIG")"
touch "$CONFIG"

# Borrar layout previo con el mismo nombre (idempotencia: el script se puede
# ejecutar múltiples veces sin acumular layouts duplicados).
python3 - "$CONFIG" <<'PYEOF'
import sys, re
path = sys.argv[1]
with open(path) as f:
    content = f.read()
pattern = re.compile(
    r'(^  \[\[multi_pane\]\].*?)(?=^  \[\[|^\[|\Z)',
    re.MULTILINE | re.DOTALL
)
content = pattern.sub('', content)
with open(path, 'w') as f:
    f.write(content)
PYEOF

# Asegurar que exista la sección [layouts]
grep -q '^\[layouts\]' "$CONFIG" || echo -e "\n[layouts]" >> "$CONFIG"

# Insertar el layout nuevo justo después de [layouts].
# El layout define una división horizontal (HPaned) al 50%, y el lado
# derecho se divide verticalmente (VPaned) en dos paneles.
#
#   ┌─────────────┬─────────────┐
#   │             │  TOP-RIGHT  │
#   │    LEFT     ├─────────────┤
#   │             │BOTTOM-RIGHT │
#   └─────────────┴─────────────┘
python3 - "$CONFIG" "$ARG" "$RC_LEFT" "$RC_TOP_RIGHT" "$RC_BOTTOM_RIGHT" <<'PYEOF'
import sys
path, arg, rc_l, rc_tr, rc_br = sys.argv[1:]
layout = f"""  [[multi_pane]]
    [[[window0]]]
      type = Window
      parent = ""
      title = Multi-pane {arg}
    [[[child1]]]
      type = HPaned
      parent = window0
      ratio = 0.5
    [[[left]]]
      type = Terminal
      parent = child1
      order = 0
      profile = default
      title = LEFT - {arg}
      command = bash --rcfile {rc_l}
    [[[child2]]]
      type = VPaned
      parent = child1
      order = 1
      ratio = 0.5
    [[[top_right]]]
      type = Terminal
      parent = child2
      order = 0
      profile = default
      title = TOP RIGHT - {arg}
      command = bash --rcfile {rc_tr}
    [[[bottom_right]]]
      type = Terminal
      parent = child2
      order = 1
      profile = default
      title = BOTTOM RIGHT - {arg}
      command = bash --rcfile {rc_br}
"""
with open(path) as f:
    content = f.read()
content = content.replace('[layouts]\n', '[layouts]\n' + layout, 1)
with open(path, 'w') as f:
    f.write(content)
PYEOF

# Lanzar Terminator desconectado de la shell padre:
#   --no-dbus    : evita que una instancia existente capture la invocación
#   --maximise   : abre la ventana maximizada
#   nohup + &    : sobrevive al cierre de la shell padre
#   disown       : libera la shell para que pueda cerrarse sin advertencias
nohup terminator --no-dbus --maximise -l multi_pane </dev/null >/dev/null 2>&1 &
disown

Enter fullscreen mode Exit fullscreen mode

You invoke it as ./multi-pane.sh prod and the argument propagates into
every pane title and command. The same script works for staging, dev, or
any environment label you want.

Why Terminator and not tmux?

tmux is more powerful, scriptable, and works over SSH. But tmux has a
learning curve, lives inside one terminal window, and isn't something most
people want to launch from a desktop shortcut.

Terminator is a GUI terminal emulator that supports persistent layouts via a
config file. It's perfect when you want a desktop launcher that opens a
specific multi-pane setup with one command — and you want the result to feel
like a normal application window, not an embedded multiplexer.