Skip to content

Commit d7aed62

Browse files
committed
Add TurtleTerm product profile
1 parent cc533f9 commit d7aed62

1 file changed

Lines changed: 142 additions & 0 deletions

File tree

assets/sourceos/turtleterm.lua

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
-- TurtleTerm default profile
2+
--
3+
-- Product-facing profile for TurtleTerm. This file is installed as
4+
-- etc/turtle-term/turtleterm.lua and loaded by the turtleterm launcher.
5+
6+
local wezterm = require 'wezterm'
7+
local mux = wezterm.mux
8+
local act = wezterm.action
9+
10+
local config = wezterm.config_builder()
11+
12+
local function env(name, fallback)
13+
local value = os.getenv(name)
14+
if value == nil or value == '' then
15+
return fallback
16+
end
17+
return value
18+
end
19+
20+
local function basename(path)
21+
if path == nil then
22+
return ''
23+
end
24+
return string.gsub(path, '(.*[/\\])', '')
25+
end
26+
27+
local function turtle_workspace()
28+
return env('SOURCEOS_WORKSPACE', 'turtle')
29+
end
30+
31+
local function turtle_domain()
32+
return env('SOURCEOS_EXECUTION_DOMAIN', 'host')
33+
end
34+
35+
local function turtle_session_id()
36+
return env('SOURCEOS_TERMINAL_SESSION_ID', '')
37+
end
38+
39+
config.default_prog = nil
40+
config.automatically_reload_config = true
41+
config.check_for_updates = false
42+
config.color_scheme = env('TURTLETERM_COLOR_SCHEME', env('SOURCEOS_TERMINAL_COLOR_SCHEME', 'Builtin Solarized Dark'))
43+
config.font = wezterm.font_with_fallback({
44+
'JetBrains Mono',
45+
'Symbols Nerd Font Mono',
46+
'Noto Color Emoji',
47+
})
48+
config.font_size = tonumber(env('TURTLETERM_FONT_SIZE', env('SOURCEOS_TERMINAL_FONT_SIZE', '12.5')))
49+
50+
config.window_padding = {
51+
left = 8,
52+
right = 8,
53+
top = 6,
54+
bottom = 6,
55+
}
56+
57+
config.use_fancy_tab_bar = false
58+
config.hide_tab_bar_if_only_one_tab = false
59+
config.tab_bar_at_bottom = false
60+
config.window_decorations = 'RESIZE'
61+
config.audible_bell = 'Disabled'
62+
config.enable_scroll_bar = false
63+
config.scrollback_lines = 20000
64+
65+
config.unix_domains = {
66+
{
67+
name = 'turtle-local',
68+
},
69+
}
70+
71+
config.set_environment_variables = {
72+
SOURCEOS_TERMINAL_FRONTEND = 'turtle-term',
73+
SOURCEOS_TERMINAL_PROFILE = 'turtleterm-v0',
74+
TURTLETERM_PROFILE = 'turtleterm-v0',
75+
}
76+
77+
config.keys = {
78+
{ key = 'Enter', mods = 'CTRL|SHIFT', action = act.SplitVertical { domain = 'CurrentPaneDomain' } },
79+
{ key = 'Enter', mods = 'CTRL|ALT', action = act.SplitHorizontal { domain = 'CurrentPaneDomain' } },
80+
{ key = 'w', mods = 'CTRL|SHIFT', action = act.CloseCurrentPane { confirm = true } },
81+
{ key = 't', mods = 'CTRL|SHIFT', action = act.SpawnTab 'CurrentPaneDomain' },
82+
{ key = 'LeftArrow', mods = 'CTRL|SHIFT', action = act.ActivateTabRelative(-1) },
83+
{ key = 'RightArrow', mods = 'CTRL|SHIFT', action = act.ActivateTabRelative(1) },
84+
{ key = 'h', mods = 'CTRL|SHIFT', action = act.ActivatePaneDirection 'Left' },
85+
{ key = 'j', mods = 'CTRL|SHIFT', action = act.ActivatePaneDirection 'Down' },
86+
{ key = 'k', mods = 'CTRL|SHIFT', action = act.ActivatePaneDirection 'Up' },
87+
{ key = 'l', mods = 'CTRL|SHIFT', action = act.ActivatePaneDirection 'Right' },
88+
{ key = 'f', mods = 'CTRL|SHIFT', action = act.Search 'CurrentSelectionOrEmptyString' },
89+
{ key = 'x', mods = 'CTRL|SHIFT', action = act.ActivateCopyMode },
90+
{ key = 'p', mods = 'CTRL|SHIFT', action = act.ActivateCommandPalette },
91+
{ key = 'o', mods = 'CTRL|SHIFT', action = act.ShowLauncher },
92+
{
93+
key = 's',
94+
mods = 'CTRL|SHIFT',
95+
action = act.PromptInputLine {
96+
description = 'TurtleTerm session note',
97+
action = wezterm.action_callback(function(window, pane, line)
98+
if line and line ~= '' then
99+
wezterm.log_info('turtleterm.session_note: ' .. line)
100+
end
101+
end),
102+
},
103+
},
104+
}
105+
106+
wezterm.on('format-tab-title', function(tab, tabs, panes, config_, hover, max_width)
107+
local pane = tab.active_pane
108+
local cwd = ''
109+
110+
if pane and pane.current_working_dir then
111+
cwd = basename(tostring(pane.current_working_dir))
112+
end
113+
114+
if cwd == '' then
115+
cwd = 'terminal'
116+
end
117+
118+
local domain = turtle_domain()
119+
local workspace = turtle_workspace()
120+
return string.format(' 🐢 %s:%s [%s] ', workspace, cwd, domain)
121+
end)
122+
123+
wezterm.on('update-right-status', function(window, pane)
124+
local workspace = turtle_workspace()
125+
local domain = turtle_domain()
126+
local session = turtle_session_id()
127+
128+
if session ~= '' then
129+
session = ' · ' .. session
130+
end
131+
132+
window:set_right_status(string.format(' 🐢 %s · %s%s ', workspace, domain, session))
133+
end)
134+
135+
wezterm.on('gui-startup', function(cmd)
136+
local workspace = turtle_workspace()
137+
pcall(function()
138+
mux.set_active_workspace(workspace)
139+
end)
140+
end)
141+
142+
return config

0 commit comments

Comments
 (0)