-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·168 lines (155 loc) · 7.78 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·168 lines (155 loc) · 7.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/zsh
set -u
setopt NULL_GLOB
YES=0
for arg in "$@"; do
case "$arg" in
--yes|-y) YES=1 ;;
--help|-h)
print "Usage: ./install.sh [--yes]"
exit 0
;;
*) print -u2 "Unknown argument: $arg"; exit 2 ;;
esac
done
[[ -n "${HOME:-}" ]] || { print -u2 "HOME is not set"; exit 1; }
repo_dir="${0:A:h}"
source_manager="$repo_dir/session-manager.zsh"
source_lib="$repo_dir/session-manager-lib.zsh"
source_install_lib="$repo_dir/install-lib.sh"
source_package_json="$repo_dir/package.json"
source_early_manager="$repo_dir/session-manager-early.zsh"
source_v01_manager="$repo_dir/session-manager-v0.1.zsh"
source_reaper="$repo_dir/reaper.sh"
source_poller="$repo_dir/poller.sh"
source_wrapper="$repo_dir/cli/ghostty-zmx"
source_uninstall="$repo_dir/uninstall.sh"
source_server_install="$repo_dir/install-server.sh"
source_remote_layout="$repo_dir/cli/remote-layout"
source_terminfo="$repo_dir/terminfo/xterm-ghostty.terminfo"
install_dir="$HOME/.config/ghostty-zmx"
manager_dest="$install_dir/session-manager.zsh"
lib_dest="$install_dir/session-manager-lib.zsh"
install_lib_dest="$install_dir/install-lib.sh"
early_manager_dest="$install_dir/session-manager-early.zsh"
v01_manager_dest="$install_dir/session-manager-v0.1.zsh"
reaper_dest="$install_dir/reaper.sh"
poller_dest="$install_dir/poller.sh"
wrapper_dest="$install_dir/cli/ghostty-zmx"
uninstall_dest="$install_dir/uninstall.sh"
server_install_dest="$install_dir/install-server.sh"
remote_layout_dest="$install_dir/cli/remote-layout"
terminfo_dest="$install_dir/terminfo/xterm-ghostty.terminfo"
zshrc="$HOME/.zshrc"
zprofile="$HOME/.zprofile"
ghostty_config="${GHOSTTY_ZMX_INTERNAL_TEST_GHOSTTY_CONFIG:-$HOME/Library/Application Support/com.mitchellh.ghostty/config.ghostty}"
source_line='[[ -r "$HOME/.config/ghostty-zmx/session-manager.zsh" ]] && source "$HOME/.config/ghostty-zmx/session-manager.zsh"'
early_source_line='[[ -r "$HOME/.config/ghostty-zmx/session-manager-early.zsh" ]] && source "$HOME/.config/ghostty-zmx/session-manager-early.zsh"'
# Shared helpers (backup_file, confirm, require_command, validate_install_dir,
# ensure/remove_source_line, strip_managed_block, ensure_ghostty_block,
# probe_ghostty_capability, refresh_vendored_terminfo, managed_block constant).
# Sourced by install.sh, install-dev.sh, and the `ghostty-zmx debug` subcommand.
source "${0:A:h}/install-lib.sh"
print_plan() {
print "ghostty-zmx installer will:"
print " - verify zmx, osascript, and zsh"
print " - install files under $install_dir"
print " - refresh the vendored Ghostty terminfo from the installed Ghostty"
print " - update $zshrc with one guarded source line"
print " - update $zprofile with an early-inherit guarded source line"
print " - update only the managed ghostty-zmx section in $ghostty_config"
print " - warn about unsupported or conflicting Ghostty settings outside the managed section"
print ""
print "To enable remote panes, run: ghostty-zmx install-server <host> on each remote host."
print ""
print "Managed Ghostty block to add:"
print -r -- "$managed_block"
}
[[ -f "$source_manager" ]] || { print -u2 "Missing $source_manager"; exit 1; }
[[ -f "$source_lib" ]] || { print -u2 "Missing $source_lib"; exit 1; }
[[ -f "$source_install_lib" ]] || { print -u2 "Missing $source_install_lib"; exit 1; }
[[ -f "$source_package_json" ]] || { print -u2 "Missing $source_package_json"; exit 1; }
[[ -f "$source_early_manager" ]] || { print -u2 "Missing $source_early_manager"; exit 1; }
[[ -f "$source_v01_manager" ]] || { print -u2 "Missing $source_v01_manager"; exit 1; }
[[ -f "$source_reaper" ]] || { print -u2 "Missing $source_reaper"; exit 1; }
[[ -f "$source_poller" ]] || { print -u2 "Missing $source_poller"; exit 1; }
[[ -f "$source_wrapper" ]] || { print -u2 "Missing $source_wrapper"; exit 1; }
[[ -f "$source_uninstall" ]] || { print -u2 "Missing $source_uninstall"; exit 1; }
[[ -f "$source_server_install" ]] || { print -u2 "Missing $source_server_install"; exit 1; }
[[ -f "$source_remote_layout" ]] || { print -u2 "Missing $source_remote_layout"; exit 1; }
# All cli/ subcommand files must exist (glob so new subcommands are caught).
[[ -d "$repo_dir/cli" && -n "$(print -r "$repo_dir/cli"/*(N))" ]] || { print -u2 "Missing cli/ subcommand files"; exit 1; }
local _cli_f
for _cli_f in "$repo_dir"/cli/*(N); do
[[ -f "$_cli_f" ]] || { print -u2 "Missing $_cli_f"; exit 1; }
done
[[ -f "$source_terminfo" ]] || { print -u2 "Missing $source_terminfo"; exit 1; }
require_command zmx
require_command osascript
require_command zsh
validate_install_dir
# Best-effort capability probe. Warn (do not refuse) if the running Ghostty
# lacks the 1.4.0 tty/pid AppleScript capability — remote features and
# tty-based identity will be inactive, and 1.3.x surfaces fall back to v0.1.
probe_ghostty_capability
print_plan
confirm "Apply this installation plan?" || { print "Installation declined; no files changed."; exit 0; }
backup_file "$zshrc"
ensure_source_line "$zshrc" || exit 1
backup_file "$zprofile"
# v0.2.0-rc migrated the early inherit hook from the full manager to a
# dedicated .zprofile entry. Older development/prerelease installs may have
# sourced session-manager.zsh from .zprofile; remove that stale line so the
# full manager is not loaded before the early hook.
remove_source_line "$zprofile" "$source_line" || exit 1
ensure_source_line "$zprofile" "$early_source_line" || exit 1
validate_install_dir
mkdir -p "$install_dir/cli" || exit 1
validate_install_dir
install -m 0644 "$source_manager" "$manager_dest" || exit 1
install -m 0644 "$source_lib" "$lib_dest" || exit 1
install -m 0644 "$source_install_lib" "$install_lib_dest" || exit 1
install -m 0644 "$source_package_json" "$install_dir/package.json" || exit 1
install -m 0644 "$source_early_manager" "$early_manager_dest" || exit 1
install -m 0644 "$source_v01_manager" "$v01_manager_dest" || exit 1
install -m 0755 "$source_reaper" "$reaper_dest" || exit 1
install -m 0755 "$source_poller" "$poller_dest" || exit 1
install -m 0755 "$source_wrapper" "$wrapper_dest" || exit 1
install -m 0755 "$source_uninstall" "$uninstall_dest" || exit 1
install -m 0755 "$source_server_install" "$server_install_dest" || exit 1
install -m 0755 "$source_remote_layout" "$remote_layout_dest" || exit 1
# Install the remaining cli/ subcommand files (install-server, debug, and any
# future subcommands). Glob-driven so adding a subcommand requires no edit here.
local _cli_src _cli_basename
for _cli_src in "$repo_dir"/cli/*(N); do
_cli_basename="${_cli_src:t}"
[[ "$_cli_basename" == "ghostty-zmx" || "$_cli_basename" == "remote-layout" ]] && continue
install -m 0755 "$_cli_src" "$install_dir/cli/$_cli_basename" || exit 1
done
# Refresh the vendored Ghostty terminfo from the installed Ghostty at install
# time so the copy always matches the laptop's Ghostty version (per the v0.2
# design, "Vendored terminfo staleness"). If infocmp against the installed
# Ghostty fails, fall back to the repo's committed copy.
refresh_vendored_terminfo "$terminfo_dest" "$source_terminfo" || exit 1
print "Installed $manager_dest"
print "Installed $lib_dest"
print "Installed $install_lib_dest"
print "Installed $install_dir/package.json"
print "Installed $early_manager_dest"
print "Installed $v01_manager_dest"
print "Installed $reaper_dest"
print "Installed $poller_dest"
print "Installed $wrapper_dest"
print "Installed $uninstall_dest"
print "Installed $server_install_dest"
print "Installed $remote_layout_dest"
for _cli_src in "$repo_dir"/cli/*(N); do
_cli_basename="${_cli_src:t}"
[[ "$_cli_basename" == "ghostty-zmx" || "$_cli_basename" == "remote-layout" ]] && continue
print "Installed $install_dir/cli/$_cli_basename"
done
print "Installed $terminfo_dest"
backup_file "$ghostty_config"
ensure_ghostty_block "$ghostty_config"
print ""
print "ghostty-zmx installation complete. Restart Ghostty or open a new Ghostty window to start managed sessions."