Copy-and-paste examples for common automation tasks.
Add these to ~/.config/nexterm/nexterm.lua (Linux/macOS) or
%APPDATA%\nexterm\nexterm.lua (Windows).
Every macro function receives (session, pane_id) and returns the string to
send to the PTY. A trailing \n presses Enter.
-- TOML: [[macros]] name="hello" fn="macro_hello" key="ctrl+alt+h"
function macro_hello(session, pane_id)
return "echo Hello from nexterm!\n"
endfunction macro_git_status(session, pane_id)
return "git status --short && git log --oneline -5\n"
endTOML entry:
[[macros]]
name = "git status"
fn = "macro_git_status"
key = "ctrl+alt+g"function macro_venv(session, pane_id)
return "source .venv/bin/activate\n"
endTOML entry:
[[macros]]
name = "venv activate"
fn = "macro_venv"
key = "ctrl+alt+v"local _compose_up = false
function macro_compose_toggle(session, pane_id)
if _compose_up then
_compose_up = false
return "docker compose down\n"
else
_compose_up = true
return "docker compose up -d\n"
end
endUse the hook on_pane_open plus the broadcast feature.
function macro_broadcast_enable(session, pane_id)
-- Enable broadcast mode: every keystroke goes to all panes
return "\x02*" -- Ctrl+B then *
end
function macro_broadcast_disable(session, pane_id)
return "\x02*"
endfunction macro_split_here(session, pane_id)
-- Get current directory from the environment (set by your shell prompt)
local cwd = os.getenv("PWD") or "~"
-- Split vertically then cd into the same directory
-- Uses escape sequence to trigger SplitVertical (\x02%) then sends cd
return "\x02%cd " .. cwd .. "\n"
endfunction macro_tail_log(session, pane_id)
-- Split horizontally and tail the most recent log file
return "\x02\"tail -f /var/log/syslog\n"
endStatus bar widgets return a string to display in the bar.
# nexterm.toml
[status_bar]
enabled = true
[[status_bar.widgets]]
kind = "lua"
fn = "widget_git_branch"
width = 24function widget_git_branch()
local handle = io.popen("git symbolic-ref --short HEAD 2>/dev/null")
if not handle then return "" end
local branch = handle:read("*l") or ""
handle:close()
if branch == "" then return "" end
return " \xef\x90\xa0 " .. branch .. " " -- nerd font git icon
endfunction widget_cpu()
local handle = io.popen(
"top -bn1 2>/dev/null | grep 'Cpu(s)' | awk '{print $2}'"
)
if not handle then return "CPU:?" end
local val = handle:read("*l") or "?"
handle:close()
return " CPU:" .. val .. "% "
endhooks.on_pane_open = function(session, pane_id)
-- Send OSC 0 title sequence through the PTY isn't possible directly,
-- but we can log the event for external tools
io.write(string.format("[nexterm] pane %d opened in '%s'\n", pane_id, session))
endhooks.on_session_start = function(session)
-- Desktop notification via notify-send (Linux) or osascript (macOS)
local cmd
if package.config:sub(1,1) == "/" then
-- Unix-like
cmd = 'notify-send "nexterm" "Session \'' .. session .. '\' started" 2>/dev/null'
if not pcall(function() os.execute(cmd) end) then
-- macOS fallback
os.execute('osascript -e \'display notification "Session ' ..
session .. ' started" with title "nexterm"\' 2>/dev/null')
end
end
endReturn nil or "" to send nothing — useful when a macro only has side effects.
function macro_log_only(session, pane_id)
io.write("macro triggered\n")
return "" -- nothing sent to the PTY
endUse \x02 for Ctrl+B to trigger built-in prefix commands from a macro:
| Sequence | Action |
|---|---|
"\x02%" |
Split vertically |
"\x02\"" |
Split horizontally |
"\x02x" |
Close pane |
"\x02n" |
Focus next pane |
"\x02z" |
Toggle zoom |
See Lua Scripting for the full API reference.