synth-shell-theme 1.3.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- synth_shell_theme/__init__.py +7 -0
- synth_shell_theme/__main__.py +8 -0
- synth_shell_theme/assets/studio.html +1920 -0
- synth_shell_theme/cli.py +887 -0
- synth_shell_theme/core.py +1695 -0
- synth_shell_theme/ecosystem.py +537 -0
- synth_shell_theme/patches.py +1853 -0
- synth_shell_theme/paths.py +363 -0
- synth_shell_theme/separators.py +320 -0
- synth_shell_theme/server.py +506 -0
- synth_shell_theme/themes/01-screenshot-match.conf +30 -0
- synth_shell_theme/themes/02-current-live-theme.conf +30 -0
- synth_shell_theme/themes/03-dracula-punch.conf +30 -0
- synth_shell_theme/themes/04-nord-ice.conf +30 -0
- synth_shell_theme/themes/05-matrix-green.conf +30 -0
- synth_shell_theme/themes/06-amber-heat.conf +30 -0
- synth_shell_theme/themes/07-cloud-ops.conf +30 -0
- synth_shell_theme/themes/08-catppuccin-mauve.conf +30 -0
- synth_shell_theme/themes/09-solarized-night.conf +30 -0
- synth_shell_theme/themes/10-gruvbox-dark.conf +30 -0
- synth_shell_theme/themes/11-monokai-neon.conf +30 -0
- synth_shell_theme/themes/12-tokyo-night.conf +30 -0
- synth_shell_theme/themes/13-synthwave-pink.conf +30 -0
- synth_shell_theme/themes/14-forest-mint.conf +30 -0
- synth_shell_theme/themes/15-ruby-steel.conf +30 -0
- synth_shell_theme/themes/16-ice-gold.conf +30 -0
- synth_shell_theme/themes/17-aqua-slate.conf +30 -0
- synth_shell_theme/themes/18-cyber-lime.conf +30 -0
- synth_shell_theme/themes/19-lavender-sunset.conf +30 -0
- synth_shell_theme/themes/20-minimal-mono.conf +30 -0
- synth_shell_theme/themes/21-rose-pine.conf +30 -0
- synth_shell_theme/themes/22-kanagawa.conf +30 -0
- synth_shell_theme/themes/23-everforest.conf +30 -0
- synth_shell_theme/themes/24-one-dark.conf +30 -0
- synth_shell_theme/themes/25-ayu-dark.conf +30 -0
- synth_shell_theme/themes/26-nightfox.conf +30 -0
- synth_shell_theme/themes/27-palenight.conf +30 -0
- synth_shell_theme/themes/28-cyberdream.conf +30 -0
- synth_shell_theme/themes/29-moonlight.conf +30 -0
- synth_shell_theme/themes/30-poimandres.conf +30 -0
- synth_shell_theme/themes/31-tokyo-storm.conf +30 -0
- synth_shell_theme/themes/32-catppuccin-mocha.conf +30 -0
- synth_shell_theme/themes/33-nordic-aurora.conf +30 -0
- synth_shell_theme/themes/34-horizon-synth.conf +30 -0
- synth_shell_theme/themes/35-gruvbox-material.conf +30 -0
- synth_shell_theme/themes/36-oxocarbon.conf +30 -0
- synth_shell_theme/themes/37-catppuccin-latte.conf +30 -0
- synth_shell_theme/themes/38-tokyo-twilight.conf +30 -0
- synth_shell_theme/themes/39-solarized-ocean.conf +30 -0
- synth_shell_theme/themes/40-vaporwave-sunset.conf +30 -0
- synth_shell_theme/themes/41-deep-abyss.conf +30 -0
- synth_shell_theme/themes/42-sakura-blossom.conf +30 -0
- synth_shell_theme/themes/43-emerald-forest.conf +30 -0
- synth_shell_theme/themes/44-vesper.conf +30 -0
- synth_shell_theme/themes/45-cobalt-neon.conf +30 -0
- synth_shell_theme/themes/46-desert-dunes.conf +30 -0
- synth_shell_theme/themes/47-cyber-samurai.conf +30 -0
- synth_shell_theme/themes/48-glacier-mint.conf +30 -0
- synth_shell_theme/themes/49-carbon-titanium.conf +30 -0
- synth_shell_theme/themes/50-matcha-latte.conf +30 -0
- synth_shell_theme/themes/51-volcanic-magma.conf +30 -0
- synth_shell_theme/themes/52-catppuccin-frappe.conf +30 -0
- synth_shell_theme/themes/53-bioluminescence.conf +30 -0
- synth_shell_theme/themes/54-mocha-caramel.conf +30 -0
- synth_shell_theme/themes/55-neon-genesis.conf +30 -0
- synth_shell_theme/themes/56-midnight-amethyst.conf +30 -0
- synth_shell_theme/themes/57-andromeda.conf +30 -0
- synth_shell_theme/themes/58-golden-velvet.conf +30 -0
- synth_shell_theme/themes/59-miami-vice.conf +30 -0
- synth_shell_theme/themes/60-zen-garden.conf +30 -0
- synth_shell_theme/themes/61-google-cloud.conf +30 -0
- synth_shell_theme/themes/62-github-dark.conf +30 -0
- synth_shell_theme/themes/63-cyberpunk-edgerunners.conf +30 -0
- synth_shell_theme/themes/64-vscode-dark.conf +30 -0
- synth_shell_theme/themes.py +580 -0
- synth_shell_theme/tui.py +632 -0
- synth_shell_theme-1.3.9.dist-info/METADATA +261 -0
- synth_shell_theme-1.3.9.dist-info/RECORD +82 -0
- synth_shell_theme-1.3.9.dist-info/WHEEL +5 -0
- synth_shell_theme-1.3.9.dist-info/entry_points.txt +3 -0
- synth_shell_theme-1.3.9.dist-info/licenses/LICENSE +21 -0
- synth_shell_theme-1.3.9.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1853 @@
|
|
|
1
|
+
"""Idempotent runtime patches and optional installer for upstream synth-shell scripts (v1.2.0)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
import tempfile
|
|
9
|
+
from datetime import datetime
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from synth_shell_theme.paths import (
|
|
13
|
+
get_backup_dir,
|
|
14
|
+
get_config_dir,
|
|
15
|
+
get_config_path,
|
|
16
|
+
get_greeter_script_path,
|
|
17
|
+
get_prompt_script_path,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
INTERACTIVE_GUARD_LINE = (
|
|
21
|
+
'[[ "${BASH_SOURCE[0]}" != "${0}" && $- != *i* ]] && return # synth-shell-theme: interactive_guard'
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
FAST_GET_KUBE = """getKube()
|
|
25
|
+
{
|
|
26
|
+
\t# synth-shell-theme: kube_fast v139 (zero-subshell kubeconfig context + namespace + prod warning + max_kube_char)
|
|
27
|
+
\tlocal cfg="${KUBECONFIG:-}"
|
|
28
|
+
\tcfg="${cfg%%:*}"
|
|
29
|
+
\tcfg="${cfg:-$HOME/.kube/config}"
|
|
30
|
+
\t[[ -r "$cfg" ]] || return
|
|
31
|
+
\tlocal line ctx=""
|
|
32
|
+
\twhile IFS= read -r line; do
|
|
33
|
+
\t\tif [[ "$line" =~ ^current-context:[[:space:]]*(.*)$ ]]; then
|
|
34
|
+
\t\t\tctx="${BASH_REMATCH[1]}"
|
|
35
|
+
\t\t\tctx="${ctx%"${ctx##*[![:space:]]}"}"
|
|
36
|
+
\t\t\tctx="${ctx%\\"}" ; ctx="${ctx#\\"}"
|
|
37
|
+
\t\t\tctx="${ctx%\\'}" ; ctx="${ctx#\\'}"
|
|
38
|
+
\t\t\tbreak
|
|
39
|
+
\t\tfi
|
|
40
|
+
\tdone < "$cfg"
|
|
41
|
+
\t[[ -z "$ctx" ]] && return
|
|
42
|
+
\tlocal ns=""
|
|
43
|
+
\tif [[ "${SSP_KUBE_SHOW_NAMESPACE:-true}" == "true" ]]; then
|
|
44
|
+
\t\tlocal _in_ctxs=0 _cur_name="" _cur_ns=""
|
|
45
|
+
\t\twhile IFS= read -r line; do
|
|
46
|
+
\t\t\tif [[ "$line" =~ ^contexts: ]]; then
|
|
47
|
+
\t\t\t\t_in_ctxs=1; continue
|
|
48
|
+
\t\t\telif (( _in_ctxs == 1 )) && [[ "$line" =~ ^[a-zA-Z0-9_-]+: ]]; then
|
|
49
|
+
\t\t\t\t[[ "$_cur_name" == "$ctx" && -n "$_cur_ns" ]] && ns="$_cur_ns"
|
|
50
|
+
\t\t\t\tbreak
|
|
51
|
+
\t\t\tfi
|
|
52
|
+
\t\t\t(( _in_ctxs == 0 )) && continue
|
|
53
|
+
\t\t\tif [[ "$line" =~ ^[[:space:]]*-[[:space:]]+ ]]; then
|
|
54
|
+
\t\t\t\tif [[ "$_cur_name" == "$ctx" && -n "$_cur_ns" ]]; then
|
|
55
|
+
\t\t\t\t\tns="$_cur_ns"; break
|
|
56
|
+
\t\t\t\tfi
|
|
57
|
+
\t\t\t\t_cur_name=""; _cur_ns=""
|
|
58
|
+
\t\t\tfi
|
|
59
|
+
\t\t\tif [[ "$line" =~ ^[[:space:]]*-?[[:space:]]*name:[[:space:]]*(.*)$ ]]; then
|
|
60
|
+
\t\t\t\t_cur_name="${BASH_REMATCH[1]}"
|
|
61
|
+
\t\t\t\t_cur_name="${_cur_name%"${_cur_name##*[![:space:]]}"}"
|
|
62
|
+
\t\t\t\t_cur_name="${_cur_name%\\"}" ; _cur_name="${_cur_name#\\"}"
|
|
63
|
+
\t\t\t\t_cur_name="${_cur_name%\\'}" ; _cur_name="${_cur_name#\\'}"
|
|
64
|
+
\t\t\telif [[ "$line" =~ ^[[:space:]]*namespace:[[:space:]]*(.*)$ ]]; then
|
|
65
|
+
\t\t\t\t_cur_ns="${BASH_REMATCH[1]}"
|
|
66
|
+
\t\t\t\t_cur_ns="${_cur_ns%"${_cur_ns##*[![:space:]]}"}"
|
|
67
|
+
\t\t\t\t_cur_ns="${_cur_ns%\\"}" ; _cur_ns="${_cur_ns#\\"}"
|
|
68
|
+
\t\t\t\t_cur_ns="${_cur_ns%\\'}" ; _cur_ns="${_cur_ns#\\'}"
|
|
69
|
+
\t\t\tfi
|
|
70
|
+
\t\tdone < "$cfg"
|
|
71
|
+
\t\t[[ -z "$ns" && "$_cur_name" == "$ctx" && -n "$_cur_ns" ]] && ns="$_cur_ns"
|
|
72
|
+
\tfi
|
|
73
|
+
\tlocal disp="$ctx"
|
|
74
|
+
\tif [[ "$disp" =~ ^gke_[^_]+_[^_]+_(.+)$ ]]; then
|
|
75
|
+
\t\tdisp="${BASH_REMATCH[1]#gke-}"
|
|
76
|
+
\tfi
|
|
77
|
+
\tif [[ -n "$ns" && "$ns" != "default" ]]; then
|
|
78
|
+
\t\tdisp="${disp} (${ns})"
|
|
79
|
+
\tfi
|
|
80
|
+
\tlocal max_k="${SSP_MAX_KUBE_CHAR:-28}"
|
|
81
|
+
\tif (( max_k > 3 && ${#disp} > max_k )); then
|
|
82
|
+
\t\tdisp="${disp:0:$((max_k - 1))}…"
|
|
83
|
+
\tfi
|
|
84
|
+
\tlocal _is_prod=0
|
|
85
|
+
\tif [[ "${SSP_KUBE_PROD_WARNING:-true}" == "true" ]]; then
|
|
86
|
+
\t\tlocal _pat="${SSP_KUBE_PROD_PATTERN:-prod|production|prd|live}"
|
|
87
|
+
\t\tlocal _had_nocase=0
|
|
88
|
+
\t\tshopt -q nocasematch && _had_nocase=1
|
|
89
|
+
\t\tshopt -s nocasematch
|
|
90
|
+
\t\t[[ "${ctx} ${ns}" =~ ($_pat) ]] && _is_prod=1
|
|
91
|
+
\t\t(( _had_nocase == 0 )) && shopt -u nocasematch
|
|
92
|
+
\tfi
|
|
93
|
+
\tif (( _is_prod == 1 )); then
|
|
94
|
+
\t\tprintf '🚨 ☸ %s' "$disp"
|
|
95
|
+
\telse
|
|
96
|
+
\t\tprintf '☸ %s' "$disp"
|
|
97
|
+
\tfi
|
|
98
|
+
}"""
|
|
99
|
+
|
|
100
|
+
SINGLE_PASS_GIT_V13 = """ # synth-shell-theme: git_single_pass v13 (WSL fast + timeout + async + counts + rebase/merge/worktree + max_git_char)
|
|
101
|
+
local _git_flags="--porcelain -b"
|
|
102
|
+
if [[ "${SSP_GIT_SKIP_UNTRACKED_ON_SLOW_FS:-true}" == "true" ]]; then
|
|
103
|
+
if [[ "$PWD" == /mnt/[a-z]/* || "$PWD" == /mnt/[a-z] ]]; then
|
|
104
|
+
_git_flags="--porcelain -b -u no"
|
|
105
|
+
elif [[ "$(git config --bool bash.showUntrackedFiles 2>/dev/null)" == "false" ]]; then
|
|
106
|
+
_git_flags="--porcelain -b -u no"
|
|
107
|
+
fi
|
|
108
|
+
fi
|
|
109
|
+
local status_out=""
|
|
110
|
+
local _git_timeout_ms="${SSP_GIT_TIMEOUT_MS:-0}"
|
|
111
|
+
if [[ "${SSP_GIT_ASYNC_CACHE:-false}" == "true" ]]; then
|
|
112
|
+
local _cache_dir="${XDG_RUNTIME_DIR:-/dev/shm}/synth-shell-git-cache"
|
|
113
|
+
[[ -d "${XDG_RUNTIME_DIR:-/dev/shm}" && -w "${XDG_RUNTIME_DIR:-/dev/shm}" ]] || _cache_dir="/tmp/synth-shell-git-cache-${UID:-0}"
|
|
114
|
+
mkdir -p "$_cache_dir" 2>/dev/null
|
|
115
|
+
local _cache_key="${PWD//\\//_}"
|
|
116
|
+
local _cache_file="${_cache_dir}/${_cache_key}.cache"
|
|
117
|
+
if [[ -r "$_cache_file" ]]; then
|
|
118
|
+
status_out="$(< "$_cache_file")"
|
|
119
|
+
(
|
|
120
|
+
local _fresh
|
|
121
|
+
_fresh="$(git status $_git_flags 2>/dev/null)"
|
|
122
|
+
printf '%s' "$_fresh" > "${_cache_file}.tmp.$$" && mv -f "${_cache_file}.tmp.$$" "$_cache_file"
|
|
123
|
+
) >/dev/null 2>&1 &
|
|
124
|
+
disown 2>/dev/null || true
|
|
125
|
+
else
|
|
126
|
+
status_out="$(git status $_git_flags 2>/dev/null)"
|
|
127
|
+
printf '%s' "$status_out" > "$_cache_file" 2>/dev/null
|
|
128
|
+
fi
|
|
129
|
+
elif (( _git_timeout_ms > 0 )) && command -v timeout >/dev/null 2>&1; then
|
|
130
|
+
local _t_sec
|
|
131
|
+
printf -v _t_sec '%d.%03d' $(( _git_timeout_ms / 1000 )) $(( _git_timeout_ms % 1000 ))
|
|
132
|
+
status_out="$(timeout "${_t_sec}s" git status $_git_flags 2>/dev/null)"
|
|
133
|
+
else
|
|
134
|
+
status_out="$(git status $_git_flags 2>/dev/null)"
|
|
135
|
+
fi
|
|
136
|
+
local is_dirty=false
|
|
137
|
+
[[ "$status_out" =~ $'\\n' ]] && is_dirty=true
|
|
138
|
+
local branch_line="${status_out%%$'\\n'*}"
|
|
139
|
+
local is_ahead=false is_behind=false _ahead_n="" _behind_n=""
|
|
140
|
+
if [[ "$branch_line" =~ ahead[[:space:]]+([0-9]+) ]]; then
|
|
141
|
+
is_ahead=true
|
|
142
|
+
_ahead_n="${BASH_REMATCH[1]}"
|
|
143
|
+
elif [[ "$branch_line" == *"ahead"* ]]; then
|
|
144
|
+
is_ahead=true
|
|
145
|
+
fi
|
|
146
|
+
if [[ "$branch_line" =~ behind[[:space:]]+([0-9]+) ]]; then
|
|
147
|
+
is_behind=true
|
|
148
|
+
_behind_n="${BASH_REMATCH[1]}"
|
|
149
|
+
elif [[ "$branch_line" == *"behind"* ]]; then
|
|
150
|
+
is_behind=true
|
|
151
|
+
fi
|
|
152
|
+
local _max_g="${SSP_MAX_GIT_CHAR:-0}"
|
|
153
|
+
if (( _max_g > 3 )) && [[ -n "${branch:-}" ]] && (( ${#branch} > _max_g )); then
|
|
154
|
+
branch="${branch:0:$((_max_g - 1))}…"
|
|
155
|
+
fi
|
|
156
|
+
if [[ "${SSP_GIT_SHOW_COUNTS:-true}" == "true" ]]; then
|
|
157
|
+
local _ab_counts=""
|
|
158
|
+
[[ -n "$_ahead_n" ]] && _ab_counts+=" ↑${_ahead_n}"
|
|
159
|
+
[[ -n "$_behind_n" ]] && _ab_counts+=" ↓${_behind_n}"
|
|
160
|
+
[[ -n "$_ab_counts" ]] && branch="${branch}${_ab_counts}"
|
|
161
|
+
fi
|
|
162
|
+
if [[ "${SSP_GIT_SHOW_STATE:-true}" == "true" ]]; then
|
|
163
|
+
local _gwalk="$PWD" _gdir="" _wt_name="" _gstep=0
|
|
164
|
+
while [[ -n "$_gwalk" && $_gstep -lt 15 ]]; do
|
|
165
|
+
if [[ -d "${_gwalk}/.git" ]]; then
|
|
166
|
+
_gdir="${_gwalk}/.git"
|
|
167
|
+
break
|
|
168
|
+
elif [[ -f "${_gwalk}/.git" ]]; then
|
|
169
|
+
local _gline=""
|
|
170
|
+
IFS= read -r _gline < "${_gwalk}/.git"
|
|
171
|
+
if [[ "$_gline" == gitdir:* ]]; then
|
|
172
|
+
_gdir="${_gline#gitdir:}"
|
|
173
|
+
_gdir="${_gdir#"${_gdir%%[![:space:]]*}"}"
|
|
174
|
+
[[ "$_gdir" != /* ]] && _gdir="${_gwalk}/${_gdir}"
|
|
175
|
+
if [[ "$_gdir" == */worktrees/* ]]; then
|
|
176
|
+
_wt_name="${_gdir##*/worktrees/}"
|
|
177
|
+
_wt_name="${_wt_name%%/*}"
|
|
178
|
+
fi
|
|
179
|
+
fi
|
|
180
|
+
break
|
|
181
|
+
fi
|
|
182
|
+
[[ "$_gwalk" == "/" ]] && break
|
|
183
|
+
_gwalk="${_gwalk%/*}"
|
|
184
|
+
[[ -z "$_gwalk" ]] && _gwalk="/"
|
|
185
|
+
_gstep=$((_gstep + 1))
|
|
186
|
+
done
|
|
187
|
+
if [[ -n "$_gdir" ]]; then
|
|
188
|
+
local _gstate=""
|
|
189
|
+
if [[ -d "${_gdir}/rebase-merge" ]]; then
|
|
190
|
+
local _rn="" _re=""
|
|
191
|
+
[[ -r "${_gdir}/rebase-merge/msgnum" ]] && IFS= read -r _rn < "${_gdir}/rebase-merge/msgnum"
|
|
192
|
+
[[ -r "${_gdir}/rebase-merge/end" ]] && IFS= read -r _re < "${_gdir}/rebase-merge/end"
|
|
193
|
+
_gstate="REBASE${_rn:+ ${_rn}/${_re}}"
|
|
194
|
+
elif [[ -d "${_gdir}/rebase-apply" ]]; then
|
|
195
|
+
_gstate="REBASE"
|
|
196
|
+
elif [[ -f "${_gdir}/MERGE_HEAD" ]]; then
|
|
197
|
+
_gstate="MERGE"
|
|
198
|
+
elif [[ -f "${_gdir}/CHERRY_PICK_HEAD" ]]; then
|
|
199
|
+
_gstate="CHERRY"
|
|
200
|
+
elif [[ -f "${_gdir}/BISECT_LOG" ]]; then
|
|
201
|
+
_gstate="BISECT"
|
|
202
|
+
fi
|
|
203
|
+
[[ -n "$_wt_name" ]] && branch="${branch} ⎇${_wt_name}"
|
|
204
|
+
[[ -n "$_gstate" ]] && branch="${branch} | ${_gstate}"
|
|
205
|
+
fi
|
|
206
|
+
fi"""
|
|
207
|
+
|
|
208
|
+
PATCHED_COLOR_CODES = """getColorCode()
|
|
209
|
+
{
|
|
210
|
+
\t# synth-shell-theme: color_256_parity truecolor_24bit
|
|
211
|
+
\tlocal COLOR="${1:-}"
|
|
212
|
+
\tif [ -z "$COLOR" ]; then
|
|
213
|
+
\t\techo 39
|
|
214
|
+
\t\treturn
|
|
215
|
+
\tfi
|
|
216
|
+
\tif [[ "$COLOR" =~ ^#([0-9a-fA-F]{6})$ ]]; then
|
|
217
|
+
\t\tlocal h="${BASH_REMATCH[1]}"
|
|
218
|
+
\t\tlocal r=$((16#${h:0:2})) g=$((16#${h:2:2})) b=$((16#${h:4:2}))
|
|
219
|
+
\t\tif [[ "${COLORTERM:-}" == "truecolor" || "${COLORTERM:-}" == "24bit" ]]; then
|
|
220
|
+
\t\t\techo "38;2;${r};${g};${b}"
|
|
221
|
+
\t\telse
|
|
222
|
+
\t\t\techo "38;5;$(( 16 + 36*(r*5/255) + 6*(g*5/255) + (b*5/255) ))"
|
|
223
|
+
\t\tfi
|
|
224
|
+
\t\treturn
|
|
225
|
+
\tfi
|
|
226
|
+
\tif [ "$COLOR" -eq "$COLOR" ] 2> /dev/null; then
|
|
227
|
+
\t\tif [ "$COLOR" -ge 0 -a "$COLOR" -lt 256 ]; then
|
|
228
|
+
\t\t\techo "38;5;$COLOR"
|
|
229
|
+
\t\telse
|
|
230
|
+
\t\t\techo 39
|
|
231
|
+
\t\tfi
|
|
232
|
+
\telse
|
|
233
|
+
\t\tcase $COLOR in
|
|
234
|
+
\t\t\tblack) echo "38;5;0" ;;
|
|
235
|
+
\t\t\tred) echo "38;5;1" ;;
|
|
236
|
+
\t\t\tgreen) echo "38;5;2" ;;
|
|
237
|
+
\t\t\tyellow) echo "38;5;3" ;;
|
|
238
|
+
\t\t\tblue) echo "38;5;4" ;;
|
|
239
|
+
\t\t\tpurple|magenta|pink) echo "38;5;5" ;;
|
|
240
|
+
\t\t\tcyan) echo "38;5;6" ;;
|
|
241
|
+
\t\t\tlight-gray) echo "38;5;7" ;;
|
|
242
|
+
\t\t\tdark-gray) echo "38;5;8" ;;
|
|
243
|
+
\t\t\tlight-red) echo "38;5;9" ;;
|
|
244
|
+
\t\t\tlight-green) echo "38;5;10" ;;
|
|
245
|
+
\t\t\tlight-yellow) echo "38;5;11" ;;
|
|
246
|
+
\t\t\tlight-blue) echo "38;5;12" ;;
|
|
247
|
+
\t\t\tlight-purple|light-magenta) echo "38;5;13" ;;
|
|
248
|
+
\t\t\tlight-cyan) echo "38;5;14" ;;
|
|
249
|
+
\t\t\twhite) echo "38;5;15" ;;
|
|
250
|
+
\t\t\tnone|transparent|default) echo "39" ;;
|
|
251
|
+
\t\t\t*) echo "39" ;;
|
|
252
|
+
\t\tesac
|
|
253
|
+
\tfi
|
|
254
|
+
}
|
|
255
|
+
getBackgroundCode()
|
|
256
|
+
{
|
|
257
|
+
\tlocal COLOR="${1:-}"
|
|
258
|
+
\tif [ -z "$COLOR" ]; then
|
|
259
|
+
\t\techo 49
|
|
260
|
+
\t\treturn
|
|
261
|
+
\tfi
|
|
262
|
+
\tif [[ "$COLOR" =~ ^#([0-9a-fA-F]{6})$ ]]; then
|
|
263
|
+
\t\tlocal h="${BASH_REMATCH[1]}"
|
|
264
|
+
\t\tlocal r=$((16#${h:0:2})) g=$((16#${h:2:2})) b=$((16#${h:4:2}))
|
|
265
|
+
\t\tif [[ "${COLORTERM:-}" == "truecolor" || "${COLORTERM:-}" == "24bit" ]]; then
|
|
266
|
+
\t\t\techo "48;2;${r};${g};${b}"
|
|
267
|
+
\t\telse
|
|
268
|
+
\t\t\techo "48;5;$(( 16 + 36*(r*5/255) + 6*(g*5/255) + (b*5/255) ))"
|
|
269
|
+
\t\tfi
|
|
270
|
+
\t\treturn
|
|
271
|
+
\tfi
|
|
272
|
+
\tif [ "$COLOR" -eq "$COLOR" ] 2> /dev/null; then
|
|
273
|
+
\t\tif [ "$COLOR" -ge 0 -a "$COLOR" -lt 256 ]; then
|
|
274
|
+
\t\t\techo "48;5;$COLOR"
|
|
275
|
+
\t\telse
|
|
276
|
+
\t\t\techo 49
|
|
277
|
+
\t\tfi
|
|
278
|
+
\telse
|
|
279
|
+
\t\tcase $COLOR in
|
|
280
|
+
\t\t\tblack) echo "48;5;0" ;;
|
|
281
|
+
\t\t\tred) echo "48;5;1" ;;
|
|
282
|
+
\t\t\tgreen) echo "48;5;2" ;;
|
|
283
|
+
\t\t\tyellow) echo "48;5;3" ;;
|
|
284
|
+
\t\t\tblue) echo "48;5;4" ;;
|
|
285
|
+
\t\t\tpurple|magenta|pink) echo "48;5;5" ;;
|
|
286
|
+
\t\t\tcyan) echo "48;5;6" ;;
|
|
287
|
+
\t\t\tlight-gray) echo "48;5;7" ;;
|
|
288
|
+
\t\t\tdark-gray) echo "48;5;8" ;;
|
|
289
|
+
\t\t\tlight-red) echo "48;5;9" ;;
|
|
290
|
+
\t\t\tlight-green) echo "48;5;10" ;;
|
|
291
|
+
\t\t\tlight-yellow) echo "48;5;11" ;;
|
|
292
|
+
\t\t\tlight-blue) echo "48;5;12" ;;
|
|
293
|
+
\t\t\tlight-purple|light-magenta) echo "48;5;13" ;;
|
|
294
|
+
\t\t\tlight-cyan) echo "48;5;14" ;;
|
|
295
|
+
\t\t\twhite) echo "48;5;15" ;;
|
|
296
|
+
\t\t\tnone|transparent|default) echo "49" ;;
|
|
297
|
+
\t\t\t*) echo "49" ;;
|
|
298
|
+
\t\tesac
|
|
299
|
+
\tfi
|
|
300
|
+
}"""
|
|
301
|
+
|
|
302
|
+
ZERO_FORK_V12_HELPERS = """# synth-shell-theme: zero_fork_render
|
|
303
|
+
# synth-shell-theme: utf8_ps1_guard
|
|
304
|
+
# synth-shell-theme: truecolor_24bit
|
|
305
|
+
_ssp_color_var()
|
|
306
|
+
{
|
|
307
|
+
\tlocal c="${1:-}"
|
|
308
|
+
\tif [[ -z "$c" ]]; then _SSP_C="39"; return; fi
|
|
309
|
+
\tif [[ "$c" =~ ^#([0-9a-fA-F]{6})$ ]]; then
|
|
310
|
+
\t\tlocal h="${BASH_REMATCH[1]}"
|
|
311
|
+
\t\tlocal r=$((16#${h:0:2})) g=$((16#${h:2:2})) b=$((16#${h:4:2}))
|
|
312
|
+
\t\tif [[ "${COLORTERM:-}" == "truecolor" || "${COLORTERM:-}" == "24bit" ]]; then
|
|
313
|
+
\t\t\t_SSP_C="38;2;${r};${g};${b}"
|
|
314
|
+
\t\telse
|
|
315
|
+
\t\t\t_SSP_C="38;5;$(( 16 + 36*(r*5/255) + 6*(g*5/255) + (b*5/255) ))"
|
|
316
|
+
\t\tfi
|
|
317
|
+
\t\treturn
|
|
318
|
+
\tfi
|
|
319
|
+
\tif [[ "$c" =~ ^[0-9]+$ ]] && (( c >= 0 && c < 256 )); then
|
|
320
|
+
\t\t_SSP_C="38;5;$c"
|
|
321
|
+
\telse
|
|
322
|
+
\t\tcase "$c" in
|
|
323
|
+
\t\t\tblack) _SSP_C="38;5;0" ;; red) _SSP_C="38;5;1" ;;
|
|
324
|
+
\t\t\tgreen) _SSP_C="38;5;2" ;; yellow) _SSP_C="38;5;3" ;;
|
|
325
|
+
\t\t\tblue) _SSP_C="38;5;4" ;; purple|magenta|pink) _SSP_C="38;5;5" ;;
|
|
326
|
+
\t\t\tcyan) _SSP_C="38;5;6" ;; light-gray) _SSP_C="38;5;7" ;;
|
|
327
|
+
\t\t\tdark-gray) _SSP_C="38;5;8" ;; light-red) _SSP_C="38;5;9" ;;
|
|
328
|
+
\t\t\tlight-green) _SSP_C="38;5;10" ;; light-yellow) _SSP_C="38;5;11" ;;
|
|
329
|
+
\t\t\tlight-blue) _SSP_C="38;5;12" ;; light-purple|light-magenta) _SSP_C="38;5;13" ;;
|
|
330
|
+
\t\t\tlight-cyan) _SSP_C="38;5;14" ;; white) _SSP_C="38;5;15" ;;
|
|
331
|
+
\t\t\t*) _SSP_C="39" ;;
|
|
332
|
+
\t\tesac
|
|
333
|
+
\tfi
|
|
334
|
+
}
|
|
335
|
+
_ssp_bg_var()
|
|
336
|
+
{
|
|
337
|
+
\tlocal c="${1:-}"
|
|
338
|
+
\tif [[ -z "$c" ]]; then _SSP_B="49"; return; fi
|
|
339
|
+
\tif [[ "$c" =~ ^#([0-9a-fA-F]{6})$ ]]; then
|
|
340
|
+
\t\tlocal h="${BASH_REMATCH[1]}"
|
|
341
|
+
\t\tlocal r=$((16#${h:0:2})) g=$((16#${h:2:2})) b=$((16#${h:4:2}))
|
|
342
|
+
\t\tif [[ "${COLORTERM:-}" == "truecolor" || "${COLORTERM:-}" == "24bit" ]]; then
|
|
343
|
+
\t\t\t_SSP_B="48;2;${r};${g};${b}"
|
|
344
|
+
\t\telse
|
|
345
|
+
\t\t\t_SSP_B="48;5;$(( 16 + 36*(r*5/255) + 6*(g*5/255) + (b*5/255) ))"
|
|
346
|
+
\t\tfi
|
|
347
|
+
\t\treturn
|
|
348
|
+
\tfi
|
|
349
|
+
\tif [[ "$c" =~ ^[0-9]+$ ]] && (( c >= 0 && c < 256 )); then
|
|
350
|
+
\t\t_SSP_B="48;5;$c"
|
|
351
|
+
\telse
|
|
352
|
+
\t\tcase "$c" in
|
|
353
|
+
\t\t\tblack) _SSP_B="48;5;0" ;; red) _SSP_B="48;5;1" ;;
|
|
354
|
+
\t\t\tgreen) _SSP_B="48;5;2" ;; yellow) _SSP_B="48;5;3" ;;
|
|
355
|
+
\t\t\tblue) _SSP_B="48;5;4" ;; purple|magenta|pink) _SSP_B="48;5;5" ;;
|
|
356
|
+
\t\t\tcyan) _SSP_B="48;5;6" ;; light-gray) _SSP_B="48;5;7" ;;
|
|
357
|
+
\t\t\tdark-gray) _SSP_B="48;5;8" ;; light-red) _SSP_B="48;5;9" ;;
|
|
358
|
+
\t\t\tlight-green) _SSP_B="48;5;10" ;; light-yellow) _SSP_B="48;5;11" ;;
|
|
359
|
+
\t\t\tlight-blue) _SSP_B="48;5;12" ;; light-purple|light-magenta) _SSP_B="48;5;13" ;;
|
|
360
|
+
\t\t\tlight-cyan) _SSP_B="48;5;14" ;; white) _SSP_B="48;5;15" ;;
|
|
361
|
+
\t\t\t*) _SSP_B="49" ;;
|
|
362
|
+
\t\tesac
|
|
363
|
+
\tfi
|
|
364
|
+
}
|
|
365
|
+
_ssp_effect_var()
|
|
366
|
+
{
|
|
367
|
+
\tcase "${1:-}" in
|
|
368
|
+
\t\tbold|bright) _SSP_E="1" ;;
|
|
369
|
+
\t\tdim) _SSP_E="2" ;;
|
|
370
|
+
\t\titalic) _SSP_E="3" ;;
|
|
371
|
+
\t\tunderline) _SSP_E="4" ;;
|
|
372
|
+
\t\tblink) _SSP_E="5" ;;
|
|
373
|
+
\t\treverse) _SSP_E="7" ;;
|
|
374
|
+
\t\thidden) _SSP_E="8" ;;
|
|
375
|
+
\t\tstrikeout) _SSP_E="9" ;;
|
|
376
|
+
\t\t*) _SSP_E="0" ;;
|
|
377
|
+
\tesac
|
|
378
|
+
}
|
|
379
|
+
_ssp_fmt_var()
|
|
380
|
+
{
|
|
381
|
+
\tlocal fg="${1:-}" bg="${2:-}" eff="${3:-}"
|
|
382
|
+
\t_ssp_color_var "$fg"
|
|
383
|
+
\t_ssp_bg_var "$bg"
|
|
384
|
+
\tif [[ -n "$eff" ]]; then
|
|
385
|
+
\t\t_ssp_effect_var "$eff"
|
|
386
|
+
\t\t_SSP_FMT="\\[\\e[0;${_SSP_C};${_SSP_B};${_SSP_E}m\\]"
|
|
387
|
+
\telse
|
|
388
|
+
\t\t_SSP_FMT="\\[\\e[0;${_SSP_C};${_SSP_B}m\\]"
|
|
389
|
+
\tfi
|
|
390
|
+
}
|
|
391
|
+
_ssp_resolve_sep()
|
|
392
|
+
{
|
|
393
|
+
\tlocal raw="${1:-}"
|
|
394
|
+
\tif [[ -z "$raw" ]]; then
|
|
395
|
+
\t\t_SSP_SEP=">"
|
|
396
|
+
\t\treturn
|
|
397
|
+
\tfi
|
|
398
|
+
\tlocal loc="${LC_ALL:-${LC_CTYPE:-${LANG:-}}}"
|
|
399
|
+
\tif [[ "$raw" == *'\\u'* || "$raw" == *'\\U'* ]]; then
|
|
400
|
+
\t\tcase "$loc" in
|
|
401
|
+
\t\t\t*[Uu][Tt][Ff]-8*|*[Uu][Tt][Ff]8*) ;;
|
|
402
|
+
\t\t\t*)
|
|
403
|
+
\t\t\t\t_SSP_SEP=">"
|
|
404
|
+
\t\t\t\treturn
|
|
405
|
+
\t\t\t\t;;
|
|
406
|
+
\t\tesac
|
|
407
|
+
\t\tlocal decoded=""
|
|
408
|
+
\t\tprintf -v decoded '%b' "$raw"
|
|
409
|
+
\t\tif [[ "$decoded" == *'\\u'* || "$decoded" == *'\\U'* || -z "$decoded" ]]; then
|
|
410
|
+
\t\t\t_SSP_SEP=">"
|
|
411
|
+
\t\telse
|
|
412
|
+
\t\t\t_SSP_SEP="$decoded"
|
|
413
|
+
\t\tfi
|
|
414
|
+
\telse
|
|
415
|
+
\t\t_SSP_SEP="$raw"
|
|
416
|
+
\tfi
|
|
417
|
+
}
|
|
418
|
+
_ssp_print_segment_var()
|
|
419
|
+
{
|
|
420
|
+
\tlocal text="${1:-}"
|
|
421
|
+
\tlocal font_color="${2:-white}"
|
|
422
|
+
\tlocal background_color="${3:-none}"
|
|
423
|
+
\tlocal next_background_color="${4:-none}"
|
|
424
|
+
\tlocal font_effect="${SSP_FONT_EFFECT_OVERRIDE:-${5:-bold}}"
|
|
425
|
+
\tlocal sep_char="${6:-${separator_char:-}}"
|
|
426
|
+
\t_ssp_resolve_sep "$sep_char"
|
|
427
|
+
\tsep_char="$_SSP_SEP"
|
|
428
|
+
\tlocal no_color='\\[\\e[0;0m\\]'
|
|
429
|
+
\t_ssp_fmt_var "$font_color" "$background_color" "$font_effect"
|
|
430
|
+
\tlocal text_format="$_SSP_FMT"
|
|
431
|
+
\t_ssp_fmt_var "$background_color" "$next_background_color" ""
|
|
432
|
+
\tlocal separator_format="$_SSP_FMT"
|
|
433
|
+
\t_SSP_SEG_OUT="${text_format}${segment_padding:- }${text}${segment_padding:- }${separator_padding_left:-}${separator_format}${sep_char}${separator_padding_right:-}${no_color}"
|
|
434
|
+
}"""
|
|
435
|
+
|
|
436
|
+
PATCHED_PRINT_SEGMENT = """printSegment()
|
|
437
|
+
{
|
|
438
|
+
\tlocal text="${1:-}"
|
|
439
|
+
\tlocal font_color="${2:-white}"
|
|
440
|
+
\tlocal background_color="${3:-none}"
|
|
441
|
+
\tlocal next_background_color="${4:-none}"
|
|
442
|
+
\tlocal font_effect="${5:-bold}"
|
|
443
|
+
\tlocal sep_char="${6:-${separator_char:-}}"
|
|
444
|
+
\t_ssp_print_segment_var "$text" "$font_color" "$background_color" "$next_background_color" "$font_effect" "$sep_char"
|
|
445
|
+
\tprintf '%s' "$_SSP_SEG_OUT"
|
|
446
|
+
}"""
|
|
447
|
+
|
|
448
|
+
ENHANCED_GET_PYENV = """getPyenv()
|
|
449
|
+
{
|
|
450
|
+
\t# synth-shell-theme: pyenv_enhanced (pure-Bash VIRTUAL_ENV_PROMPT + pyvenv.cfg + conda + max_pyenv_char)
|
|
451
|
+
\tlocal pyenv=""
|
|
452
|
+
\tif [[ -n "${VIRTUAL_ENV_PROMPT:-}" ]]; then
|
|
453
|
+
\t\tpyenv="${VIRTUAL_ENV_PROMPT}"
|
|
454
|
+
\t\tpyenv="${pyenv#(}" ; pyenv="${pyenv%)}"
|
|
455
|
+
\t\tpyenv="${pyenv#"${pyenv%%[![:space:]]*}"}"
|
|
456
|
+
\t\tpyenv="${pyenv%"${pyenv##*[![:space:]]}"}"
|
|
457
|
+
\telif [[ -n "${VIRTUAL_ENV:-}" && -r "${VIRTUAL_ENV}/pyvenv.cfg" ]]; then
|
|
458
|
+
\t\tlocal _line
|
|
459
|
+
\t\twhile IFS= read -r _line; do
|
|
460
|
+
\t\t\tif [[ "$_line" =~ ^prompt[[:space:]]*=[[:space:]]*(.*)$ ]]; then
|
|
461
|
+
\t\t\t\tpyenv="${BASH_REMATCH[1]}"
|
|
462
|
+
\t\t\t\tpyenv="${pyenv%"${pyenv##*[![:space:]]}"}"
|
|
463
|
+
\t\t\t\tpyenv="${pyenv%\\"}" ; pyenv="${pyenv#\\"}"
|
|
464
|
+
\t\t\t\tpyenv="${pyenv%\\'}" ; pyenv="${pyenv#\\'}"
|
|
465
|
+
\t\t\t\tbreak
|
|
466
|
+
\t\t\tfi
|
|
467
|
+
\t\tdone < "${VIRTUAL_ENV}/pyvenv.cfg"
|
|
468
|
+
\tfi
|
|
469
|
+
\tif [[ -z "$pyenv" && -n "${CONDA_DEFAULT_ENV:-}" ]]; then
|
|
470
|
+
\t\tpyenv="${CONDA_DEFAULT_ENV}"
|
|
471
|
+
\telif [[ -z "$pyenv" && -n "${VIRTUAL_ENV:-}" ]]; then
|
|
472
|
+
\t\tlocal _ve="${VIRTUAL_ENV%/}"
|
|
473
|
+
\t\tpyenv="${_ve##*/}"
|
|
474
|
+
\t\tif [[ "$pyenv" == ".venv" || "$pyenv" == "venv" ]]; then
|
|
475
|
+
\t\t\tlocal _parent="${_ve%/*}"
|
|
476
|
+
\t\t\t[[ -n "$_parent" && "$_parent" != "$_ve" ]] && pyenv="${_parent##*/}"
|
|
477
|
+
\t\tfi
|
|
478
|
+
\tfi
|
|
479
|
+
\t[[ -z "$pyenv" ]] && return
|
|
480
|
+
\tlocal _max_p="${SSP_MAX_PYENV_CHAR:-0}"
|
|
481
|
+
\tif (( _max_p > 3 && ${#pyenv} > _max_p )); then
|
|
482
|
+
\t\tpyenv="${pyenv:0:$((_max_p - 1))}…"
|
|
483
|
+
\tfi
|
|
484
|
+
\tprintf '%s' "$pyenv"
|
|
485
|
+
}"""
|
|
486
|
+
|
|
487
|
+
V12_SEGMENTS_BLOCK = """# synth-shell-theme: v11_segments
|
|
488
|
+
# synth-shell-theme: v12_segments
|
|
489
|
+
# synth-shell-theme: v13_segments
|
|
490
|
+
# synth-shell-theme: responsive_width
|
|
491
|
+
# synth-shell-theme: osc133_semantic
|
|
492
|
+
# synth-shell-theme: osc7_cwd
|
|
493
|
+
# synth-shell-theme: v139_smart_features
|
|
494
|
+
# synth-shell-theme: right_prompt
|
|
495
|
+
_ssp_has_element()
|
|
496
|
+
{
|
|
497
|
+
\tlocal target="$1" item
|
|
498
|
+
\tfor item in "${SSP_ELEMENTS[@]}" "${SSP_RIGHT_ELEMENTS[@]}"; do
|
|
499
|
+
\t\t[[ "$item" == "$target" ]] && return 0
|
|
500
|
+
\tdone
|
|
501
|
+
\treturn 1
|
|
502
|
+
}
|
|
503
|
+
_ssp_auto_os_icon()
|
|
504
|
+
{
|
|
505
|
+
\tif [[ "${OSTYPE:-}" == darwin* ]]; then
|
|
506
|
+
\t\t_SSP_PREFIX=" "
|
|
507
|
+
\t\treturn
|
|
508
|
+
\tfi
|
|
509
|
+
\tlocal os_id=""
|
|
510
|
+
\tif [[ -r /etc/os-release ]]; then
|
|
511
|
+
\t\tlocal _line
|
|
512
|
+
\t\twhile IFS= read -r _line; do
|
|
513
|
+
\t\t\tif [[ "$_line" == ID=* ]]; then
|
|
514
|
+
\t\t\t\tos_id="${_line#ID=}"
|
|
515
|
+
\t\t\t\tos_id="${os_id%\\"}" ; os_id="${os_id#\\"}"
|
|
516
|
+
\t\t\t\tbreak
|
|
517
|
+
\t\t\tfi
|
|
518
|
+
\t\tdone < /etc/os-release
|
|
519
|
+
\tfi
|
|
520
|
+
\tcase "$os_id" in
|
|
521
|
+
\t\t[Uu]buntu) _SSP_PREFIX=" " ;;
|
|
522
|
+
\t\t[Dd]ebian) _SSP_PREFIX=" " ;;
|
|
523
|
+
\t\t[Aa]rch|[Ee]ndeavouros|[Mm]anjaro) _SSP_PREFIX=" " ;;
|
|
524
|
+
\t\t[Ff]edora) _SSP_PREFIX=" " ;;
|
|
525
|
+
\t\t[Nn]ixos) _SSP_PREFIX=" " ;;
|
|
526
|
+
\t\t[Aa]lpine) _SSP_PREFIX=" " ;;
|
|
527
|
+
\t\t*) _SSP_PREFIX=" " ;;
|
|
528
|
+
\tesac
|
|
529
|
+
}
|
|
530
|
+
getAws()
|
|
531
|
+
{
|
|
532
|
+
\tlocal prof="${AWS_PROFILE:-${AWS_VAULT:-${AWS_DEFAULT_PROFILE:-}}}"
|
|
533
|
+
\t[[ -z "$prof" ]] && return
|
|
534
|
+
\tprintf '☁ %s' "$prof"
|
|
535
|
+
}
|
|
536
|
+
getGcp()
|
|
537
|
+
{
|
|
538
|
+
\tlocal proj="${CLOUDSDK_CORE_PROJECT:-${GOOGLE_CLOUD_PROJECT:-}}"
|
|
539
|
+
\tif [[ -z "$proj" ]]; then
|
|
540
|
+
\t\tlocal gdir="${CLOUDSDK_CONFIG:-$HOME/.config/gcloud}"
|
|
541
|
+
\t\tif [[ -r "${gdir}/active_config" ]]; then
|
|
542
|
+
\t\t\tlocal active_cfg=""
|
|
543
|
+
\t\t\tIFS= read -r active_cfg < "${gdir}/active_config"
|
|
544
|
+
\t\t\tlocal cfg_file="${gdir}/configurations/config_${active_cfg}"
|
|
545
|
+
\t\t\tif [[ -r "$cfg_file" ]]; then
|
|
546
|
+
\t\t\t\tlocal _line
|
|
547
|
+
\t\t\t\twhile IFS= read -r _line; do
|
|
548
|
+
\t\t\t\t\tif [[ "$_line" =~ ^project[[:space:]]*=[[:space:]]*(.*)$ ]]; then
|
|
549
|
+
\t\t\t\t\t\tproj="${BASH_REMATCH[1]}"
|
|
550
|
+
\t\t\t\t\t\tproj="${proj%"${proj##*[![:space:]]}"}"
|
|
551
|
+
\t\t\t\t\t\tbreak
|
|
552
|
+
\t\t\t\t\tfi
|
|
553
|
+
\t\t\t\tdone < "$cfg_file"
|
|
554
|
+
\t\t\tfi
|
|
555
|
+
\t\tfi
|
|
556
|
+
\tfi
|
|
557
|
+
\t[[ -z "$proj" ]] && return
|
|
558
|
+
\tprintf 'GCP:%s' "$proj"
|
|
559
|
+
}
|
|
560
|
+
getDocker()
|
|
561
|
+
{
|
|
562
|
+
\tlocal ctx="${DOCKER_CONTEXT:-}"
|
|
563
|
+
\tif [[ -z "$ctx" && -r "$HOME/.docker/config.json" ]]; then
|
|
564
|
+
\t\tlocal _line
|
|
565
|
+
\t\twhile IFS= read -r _line; do
|
|
566
|
+
\t\t\tif [[ "$_line" =~ \\"currentContext\\"[[:space:]]*:[[:space:]]*\\"([^\\"]+)\\" ]]; then
|
|
567
|
+
\t\t\t\tctx="${BASH_REMATCH[1]}"
|
|
568
|
+
\t\t\t\tbreak
|
|
569
|
+
\t\t\tfi
|
|
570
|
+
\t\tdone < "$HOME/.docker/config.json"
|
|
571
|
+
\tfi
|
|
572
|
+
\t[[ -z "$ctx" || "$ctx" == "default" ]] && return
|
|
573
|
+
\tprintf '🐳 %s' "$ctx"
|
|
574
|
+
}
|
|
575
|
+
getNode()
|
|
576
|
+
{
|
|
577
|
+
\t[[ -f package.json ]] || return
|
|
578
|
+
\tlocal ver=""
|
|
579
|
+
\tif [[ -n "${NVM_BIN:-}" && "$NVM_BIN" =~ /(v[0-9]+\\.[0-9]+\\.[0-9]+)/ ]]; then
|
|
580
|
+
\t\tver="${BASH_REMATCH[1]}"
|
|
581
|
+
\telif [[ -n "${FNM_MULTISHELL_PATH:-}" && "$FNM_MULTISHELL_PATH" =~ /(v[0-9]+\\.[0-9]+\\.[0-9]+) ]]; then
|
|
582
|
+
\t\tver="${BASH_REMATCH[1]}"
|
|
583
|
+
\telif [[ -r .nvmrc ]]; then
|
|
584
|
+
\t\tIFS= read -r ver < .nvmrc
|
|
585
|
+
\t\tver="${ver%"${ver##*[![:space:]]}"}"
|
|
586
|
+
\tfi
|
|
587
|
+
\t[[ -z "$ver" ]] && return
|
|
588
|
+
\tprintf '⬢ %s' "$ver"
|
|
589
|
+
}
|
|
590
|
+
getSsh()
|
|
591
|
+
{
|
|
592
|
+
\tif [[ -n "${SSH_CONNECTION:-}" || -n "${SSH_TTY:-}" ]]; then
|
|
593
|
+
\t\tprintf '⇄ ssh'
|
|
594
|
+
\telif [[ -f /.dockerenv ]]; then
|
|
595
|
+
\t\tprintf '🐳 ctr'
|
|
596
|
+
\telif [[ -f /run/.containerenv ]]; then
|
|
597
|
+
\t\tprintf '📦 pod'
|
|
598
|
+
\telif [[ -n "${CONTAINER_ID:-}" ]]; then
|
|
599
|
+
\t\tprintf '📦 %s' "$CONTAINER_ID"
|
|
600
|
+
\tfi
|
|
601
|
+
}
|
|
602
|
+
getJobs()
|
|
603
|
+
{
|
|
604
|
+
\tlocal _jlines _jcount=0 _jl
|
|
605
|
+
\t_jlines="$(jobs -p 2>/dev/null)"
|
|
606
|
+
\t[[ -z "$_jlines" ]] && return
|
|
607
|
+
\twhile IFS= read -r _jl; do
|
|
608
|
+
\t\t[[ -n "$_jl" ]] && _jcount=$((_jcount + 1))
|
|
609
|
+
\tdone <<< "$_jlines"
|
|
610
|
+
\t(( _jcount > 0 )) && printf '⚙ %d' "$_jcount"
|
|
611
|
+
}
|
|
612
|
+
getDirenv()
|
|
613
|
+
{
|
|
614
|
+
\tlocal dd="${DIRENV_DIR:-}"
|
|
615
|
+
\t[[ -z "$dd" ]] && return
|
|
616
|
+
\tdd="${dd#-}"
|
|
617
|
+
\tdd="${dd%/}"
|
|
618
|
+
\tprintf '⚡ %s' "${dd##*/}"
|
|
619
|
+
}
|
|
620
|
+
getShlvl()
|
|
621
|
+
{
|
|
622
|
+
\tif [[ -n "${IN_NIX_SHELL:-}" ]]; then
|
|
623
|
+
\t\tprintf '❄ nix'
|
|
624
|
+
\telif (( ${SHLVL:-1} > 1 )); then
|
|
625
|
+
\t\tprintf '↳ L%d' "$SHLVL"
|
|
626
|
+
\tfi
|
|
627
|
+
}
|
|
628
|
+
getRust()
|
|
629
|
+
{
|
|
630
|
+
\t[[ -f Cargo.toml ]] || return
|
|
631
|
+
\tlocal ver="${RUSTUP_TOOLCHAIN:-}"
|
|
632
|
+
\tif [[ -z "$ver" && -r rust-toolchain.toml ]]; then
|
|
633
|
+
\t\tlocal _line
|
|
634
|
+
\t\twhile IFS= read -r _line; do
|
|
635
|
+
\t\t\tif [[ "$_line" =~ channel[[:space:]]*=[[:space:]]*\\"([^\\"]+)\\" ]]; then
|
|
636
|
+
\t\t\t\tver="${BASH_REMATCH[1]}"
|
|
637
|
+
\t\t\t\tbreak
|
|
638
|
+
\t\t\tfi
|
|
639
|
+
\t\tdone < rust-toolchain.toml
|
|
640
|
+
\tfi
|
|
641
|
+
\tif [[ -z "$ver" && -r Cargo.toml ]]; then
|
|
642
|
+
\t\tlocal _line
|
|
643
|
+
\t\twhile IFS= read -r _line; do
|
|
644
|
+
\t\t\tif [[ "$_line" =~ ^rust-version[[:space:]]*=[[:space:]]*\\"([^\\"]+)\\" ]]; then
|
|
645
|
+
\t\t\t\tver="${BASH_REMATCH[1]}"
|
|
646
|
+
\t\t\t\tbreak
|
|
647
|
+
\t\t\tfi
|
|
648
|
+
\t\tdone < Cargo.toml
|
|
649
|
+
\tfi
|
|
650
|
+
\tprintf '🦀 %s' "${ver:-rs}"
|
|
651
|
+
}
|
|
652
|
+
getGo()
|
|
653
|
+
{
|
|
654
|
+
\t[[ -f go.mod ]] || return
|
|
655
|
+
\tlocal ver="" _line
|
|
656
|
+
\twhile IFS= read -r _line; do
|
|
657
|
+
\t\tif [[ "$_line" =~ ^go[[:space:]]+([0-9]+\\.[0-9]+(\\.[0-9]+)?) ]]; then
|
|
658
|
+
\t\t\tver="${BASH_REMATCH[1]}"
|
|
659
|
+
\t\t\tbreak
|
|
660
|
+
\t\tfi
|
|
661
|
+
\tdone < go.mod
|
|
662
|
+
\t[[ -z "$ver" ]] && return
|
|
663
|
+
\tprintf '🐹 %s' "$ver"
|
|
664
|
+
}
|
|
665
|
+
getBattery()
|
|
666
|
+
{
|
|
667
|
+
\tlocal bat_dir="" cap="" st=""
|
|
668
|
+
\tlocal d
|
|
669
|
+
\tfor d in /sys/class/power_supply/BAT* /sys/class/power_supply/macsmc-battery; do
|
|
670
|
+
\t\tif [[ -r "${d}/capacity" ]]; then
|
|
671
|
+
\t\t\tbat_dir="$d"
|
|
672
|
+
\t\t\tbreak
|
|
673
|
+
\t\tfi
|
|
674
|
+
\tdone
|
|
675
|
+
\t[[ -z "$bat_dir" ]] && return
|
|
676
|
+
\tIFS= read -r cap < "${bat_dir}/capacity"
|
|
677
|
+
\t[[ -r "${bat_dir}/status" ]] && IFS= read -r st < "${bat_dir}/status"
|
|
678
|
+
\t[[ ! "$cap" =~ ^[0-9]+$ ]] && return
|
|
679
|
+
\tlocal thresh="${SSP_BATTERY_THRESHOLD:-100}"
|
|
680
|
+
\t(( cap > thresh )) && return
|
|
681
|
+
\tlocal icon="🔋"
|
|
682
|
+
\tif [[ "$st" == "Charging" ]]; then
|
|
683
|
+
\t\ticon="⚡"
|
|
684
|
+
\telif (( cap <= 20 )); then
|
|
685
|
+
\t\ticon="🪫"
|
|
686
|
+
\tfi
|
|
687
|
+
\tprintf '%s %d%%' "$icon" "$cap"
|
|
688
|
+
}
|
|
689
|
+
getSudo()
|
|
690
|
+
{
|
|
691
|
+
\tcommand -v sudo >/dev/null 2>&1 || return
|
|
692
|
+
\tsudo -n true 2>/dev/null && printf '%s' "${SSP_SUDO_SYMBOL:-🔓 sudo}"
|
|
693
|
+
}
|
|
694
|
+
getJj()
|
|
695
|
+
{
|
|
696
|
+
\tlocal _w="$PWD" _st=0 _found=0
|
|
697
|
+
\twhile [[ -n "$_w" && $_st -lt 15 ]]; do
|
|
698
|
+
\t\tif [[ -d "${_w}/.jj" ]]; then _found=1; break; fi
|
|
699
|
+
\t\t[[ "$_w" == "/" ]] && break
|
|
700
|
+
\t\t_w="${_w%/*}"
|
|
701
|
+
\t\t[[ -z "$_w" ]] && _w="/"
|
|
702
|
+
\t\t_st=$((_st + 1))
|
|
703
|
+
\tdone
|
|
704
|
+
\t(( _found == 0 )) && return
|
|
705
|
+
\tlocal _jj_out=""
|
|
706
|
+
\tif command -v jj >/dev/null 2>&1; then
|
|
707
|
+
\t\t_jj_out="$(jj log -r @ --no-graph --ignore-working-copy -T 'change_id.shortest(4) ++ if(bookmarks, " " ++ bookmarks, "")' 2>/dev/null)"
|
|
708
|
+
\tfi
|
|
709
|
+
\tprintf '🥋 %s' "${_jj_out:-jj}"
|
|
710
|
+
}
|
|
711
|
+
getCustom()
|
|
712
|
+
{
|
|
713
|
+
\tlocal _val="${SYNTH_CUSTOM_BADGE:-${SSP_CUSTOM_TEXT:-}}"
|
|
714
|
+
\t[[ -z "$_val" ]] && return
|
|
715
|
+
\tprintf '%s' "$_val"
|
|
716
|
+
}
|
|
717
|
+
_ssp_shorten_path_fish()
|
|
718
|
+
{
|
|
719
|
+
\tlocal p="${1:-$PWD}"
|
|
720
|
+
\tif [[ "$p" == "$HOME" ]]; then _SSP_FISH_PATH="~"; return; fi
|
|
721
|
+
\tif [[ "$p" == "$HOME"/* ]]; then p="~${p#"$HOME"}"; fi
|
|
722
|
+
\tlocal IFS='/' _parts=() _out="" _idx=0 _last=0
|
|
723
|
+
\tread -r -a _parts <<< "$p"
|
|
724
|
+
\t_last=$(( ${#_parts[@]} - 1 ))
|
|
725
|
+
\twhile (( _idx <= _last )); do
|
|
726
|
+
\t\tlocal _seg="${_parts[$_idx]}"
|
|
727
|
+
\t\tif (( _idx == _last )); then
|
|
728
|
+
\t\t\t_out+="${_seg}"
|
|
729
|
+
\t\telif [[ -z "$_seg" ]]; then
|
|
730
|
+
\t\t\t_out+="/"
|
|
731
|
+
\t\telif [[ "$_seg" == "~" ]]; then
|
|
732
|
+
\t\t\t_out+="~/"
|
|
733
|
+
\t\telif [[ "$_seg" == .* && ${#_seg} -gt 1 ]]; then
|
|
734
|
+
\t\t\t_out+="${_seg:0:2}/"
|
|
735
|
+
\t\telse
|
|
736
|
+
\t\t\t_out+="${_seg:0:1}/"
|
|
737
|
+
\t\tfi
|
|
738
|
+
\t\t_idx=$(( _idx + 1 ))
|
|
739
|
+
\tdone
|
|
740
|
+
\t_SSP_FISH_PATH="${_out:-/}"
|
|
741
|
+
}
|
|
742
|
+
_ssp_osc7_emit()
|
|
743
|
+
{
|
|
744
|
+
\tlocal _raw="$PWD" _enc="" _i=0 _len=${#PWD} _ch="" _hex=""
|
|
745
|
+
\twhile (( _i < _len )); do
|
|
746
|
+
\t\t_ch="${_raw:_i:1}"
|
|
747
|
+
\t\tcase "$_ch" in
|
|
748
|
+
\t\t\t[a-zA-Z0-9._~/-]) _enc+="$_ch" ;;
|
|
749
|
+
\t\t\t*) printf -v _hex '%%%02X' "'$_ch" 2>/dev/null && _enc+="$_hex" || _enc+="$_ch" ;;
|
|
750
|
+
\t\tesac
|
|
751
|
+
\t\t_i=$(( _i + 1 ))
|
|
752
|
+
\tdone
|
|
753
|
+
\tprintf '\\e]7;file://%s%s\\a' "${HOSTNAME:-localhost}" "$_enc"
|
|
754
|
+
}
|
|
755
|
+
_ssp_host_color_var()
|
|
756
|
+
{
|
|
757
|
+
\t_SSP_SSH_HOST_FG=""
|
|
758
|
+
\t_SSP_SSH_HOST_BG=""
|
|
759
|
+
\t[[ "${SSP_SSH_HOST_COLOR:-false}" != "true" ]] && return
|
|
760
|
+
\t[[ -z "${SSH_CONNECTION:-}" && -z "${SSP_FORCE_SSH_COLOR:-}" ]] && return
|
|
761
|
+
\tlocal hn="${HOSTNAME:-localhost}"
|
|
762
|
+
\tlocal _had_nc=0
|
|
763
|
+
\tshopt -q nocasematch && _had_nc=1
|
|
764
|
+
\tshopt -s nocasematch
|
|
765
|
+
\tif [[ "$hn" =~ (prod|production|prd|live) ]]; then
|
|
766
|
+
\t\t_SSP_SSH_HOST_FG="white"; _SSP_SSH_HOST_BG="196"
|
|
767
|
+
\telif [[ "$hn" =~ (stg|stag|staging|uat|qa) ]]; then
|
|
768
|
+
\t\t_SSP_SSH_HOST_FG="black"; _SSP_SSH_HOST_BG="214"
|
|
769
|
+
\tfi
|
|
770
|
+
\t(( _had_nc == 0 )) && shopt -u nocasematch
|
|
771
|
+
\t[[ -n "$_SSP_SSH_HOST_BG" ]] && return
|
|
772
|
+
\tlocal _pal=(33 37 68 71 98 130 135 166 172 203 39 63)
|
|
773
|
+
\tlocal _h=0 _i=0 _c="" _n=0 _hlen=${#hn}
|
|
774
|
+
\twhile (( _i < _hlen )); do
|
|
775
|
+
\t\t_c="${hn:_i:1}"
|
|
776
|
+
\t\tprintf -v _n '%d' "'$_c" 2>/dev/null || _n=7
|
|
777
|
+
\t\t_h=$(( (_h * 31 + _n) % 12 ))
|
|
778
|
+
\t\t_i=$(( _i + 1 ))
|
|
779
|
+
\tdone
|
|
780
|
+
\t_SSP_SSH_HOST_FG="white"
|
|
781
|
+
\t_SSP_SSH_HOST_BG="${_pal[$_h]}"
|
|
782
|
+
}
|
|
783
|
+
_ssp_format_duration_var()
|
|
784
|
+
{
|
|
785
|
+
\t_SSP_DUR=""
|
|
786
|
+
\t_SSP_LAST_ELAPSED_MS=0
|
|
787
|
+
\tlocal start_ms="${_SSP_CMD_START_MS:-0}"
|
|
788
|
+
\t(( start_ms <= 0 )) && return
|
|
789
|
+
\tlocal now_ms=0
|
|
790
|
+
\tif [[ -n "${EPOCHREALTIME:-}" ]]; then
|
|
791
|
+
\t\tnow_ms=$(( ${EPOCHREALTIME/./} / 1000 ))
|
|
792
|
+
\telse
|
|
793
|
+
\t\tnow_ms=$(( SECONDS * 1000 ))
|
|
794
|
+
\tfi
|
|
795
|
+
\tlocal elapsed=$(( now_ms - start_ms ))
|
|
796
|
+
\t_SSP_LAST_ELAPSED_MS=$elapsed
|
|
797
|
+
\tlocal min_ms="${SSP_MIN_DURATION_MS:-2000}"
|
|
798
|
+
\t(( elapsed < min_ms )) && return
|
|
799
|
+
\tif (( elapsed >= 60000 )); then
|
|
800
|
+
\t\tprintf -v _SSP_DUR '⏱ %dm %ds' $(( elapsed / 60000 )) $(( (elapsed % 60000) / 1000 ))
|
|
801
|
+
\telse
|
|
802
|
+
\t\tprintf -v _SSP_DUR '⏱ %d.%ds' $(( elapsed / 1000 )) $(( (elapsed % 1000) / 100 ))
|
|
803
|
+
\tfi
|
|
804
|
+
}"""
|
|
805
|
+
|
|
806
|
+
V12_COLORS_FOR_ELEMENT = """get_colors_for_element()
|
|
807
|
+
{
|
|
808
|
+
\tcase "${1:-}" in
|
|
809
|
+
\t\t"USER") echo "${SSP_COLORS_USER[@]}" ;;
|
|
810
|
+
\t\t"HOST") echo "${SSP_COLORS_HOST[@]}" ;;
|
|
811
|
+
\t\t"PWD") echo "${SSP_COLORS_PWD[@]}" ;;
|
|
812
|
+
\t\t"GIT") echo "${SSP_COLORS_GIT[@]}" ;;
|
|
813
|
+
\t\t"PYENV") echo "${SSP_COLORS_PYENV[@]}" ;;
|
|
814
|
+
\t\t"KUBE") echo "${SSP_COLORS_KUBE[@]}" ;;
|
|
815
|
+
\t\t"TF") echo "${SSP_COLORS_TF[@]}" ;;
|
|
816
|
+
\t\t"CLOCK") echo "${SSP_COLORS_CLOCK[@]}" ;;
|
|
817
|
+
\t\t"STATUS") echo "${SSP_COLORS_STATUS[@]}" ;;
|
|
818
|
+
\t\t"DURATION") echo "${SSP_COLORS_DURATION[@]}" ;;
|
|
819
|
+
\t\t"AWS") echo "${SSP_COLORS_AWS[@]}" ;;
|
|
820
|
+
\t\t"GCP") echo "${SSP_COLORS_GCP[@]}" ;;
|
|
821
|
+
\t\t"DOCKER") echo "${SSP_COLORS_DOCKER[@]}" ;;
|
|
822
|
+
\t\t"NODE") echo "${SSP_COLORS_NODE[@]}" ;;
|
|
823
|
+
\t\t"SSH") echo "${SSP_COLORS_SSH[@]}" ;;
|
|
824
|
+
\t\t"JOBS") echo "${SSP_COLORS_JOBS[@]}" ;;
|
|
825
|
+
\t\t"DIRENV") echo "${SSP_COLORS_DIRENV[@]}" ;;
|
|
826
|
+
\t\t"SHLVL") echo "${SSP_COLORS_SHLVL[@]}" ;;
|
|
827
|
+
\t\t"RUST") echo "${SSP_COLORS_RUST[@]}" ;;
|
|
828
|
+
\t\t"GO") echo "${SSP_COLORS_GO[@]}" ;;
|
|
829
|
+
\t\t"BATTERY") echo "${SSP_COLORS_BATTERY[@]}" ;;
|
|
830
|
+
\t\t"SUDO") echo "${SSP_COLORS_SUDO[@]}" ;;
|
|
831
|
+
\t\t"JJ") echo "${SSP_COLORS_JJ[@]}" ;;
|
|
832
|
+
\t\t"CUSTOM") echo "${SSP_COLORS_CUSTOM[@]}" ;;
|
|
833
|
+
\t\t"INPUT") echo "${SSP_COLORS_INPUT[@]}" ;;
|
|
834
|
+
\t\t*) ;;
|
|
835
|
+
\tesac
|
|
836
|
+
}
|
|
837
|
+
_ssp_colors_var()
|
|
838
|
+
{
|
|
839
|
+
\tcase "${1:-}" in
|
|
840
|
+
\t\t"USER") _SSP_EL_C=("${SSP_COLORS_USER[@]}") ;;
|
|
841
|
+
\t\t"HOST") _SSP_EL_C=("${SSP_COLORS_HOST[@]}") ;;
|
|
842
|
+
\t\t"PWD") _SSP_EL_C=("${SSP_COLORS_PWD[@]}") ;;
|
|
843
|
+
\t\t"GIT") _SSP_EL_C=("${SSP_COLORS_GIT[@]}") ;;
|
|
844
|
+
\t\t"PYENV") _SSP_EL_C=("${SSP_COLORS_PYENV[@]}") ;;
|
|
845
|
+
\t\t"KUBE") _SSP_EL_C=("${SSP_COLORS_KUBE[@]}") ;;
|
|
846
|
+
\t\t"TF") _SSP_EL_C=("${SSP_COLORS_TF[@]}") ;;
|
|
847
|
+
\t\t"CLOCK") _SSP_EL_C=("${SSP_COLORS_CLOCK[@]}") ;;
|
|
848
|
+
\t\t"STATUS") _SSP_EL_C=("${SSP_COLORS_STATUS[@]}") ;;
|
|
849
|
+
\t\t"DURATION") _SSP_EL_C=("${SSP_COLORS_DURATION[@]}") ;;
|
|
850
|
+
\t\t"AWS") _SSP_EL_C=("${SSP_COLORS_AWS[@]}") ;;
|
|
851
|
+
\t\t"GCP") _SSP_EL_C=("${SSP_COLORS_GCP[@]}") ;;
|
|
852
|
+
\t\t"DOCKER") _SSP_EL_C=("${SSP_COLORS_DOCKER[@]}") ;;
|
|
853
|
+
\t\t"NODE") _SSP_EL_C=("${SSP_COLORS_NODE[@]}") ;;
|
|
854
|
+
\t\t"SSH") _SSP_EL_C=("${SSP_COLORS_SSH[@]}") ;;
|
|
855
|
+
\t\t"JOBS") _SSP_EL_C=("${SSP_COLORS_JOBS[@]}") ;;
|
|
856
|
+
\t\t"DIRENV") _SSP_EL_C=("${SSP_COLORS_DIRENV[@]}") ;;
|
|
857
|
+
\t\t"SHLVL") _SSP_EL_C=("${SSP_COLORS_SHLVL[@]}") ;;
|
|
858
|
+
\t\t"RUST") _SSP_EL_C=("${SSP_COLORS_RUST[@]}") ;;
|
|
859
|
+
\t\t"GO") _SSP_EL_C=("${SSP_COLORS_GO[@]}") ;;
|
|
860
|
+
\t\t"BATTERY") _SSP_EL_C=("${SSP_COLORS_BATTERY[@]}") ;;
|
|
861
|
+
\t\t"SUDO") _SSP_EL_C=("${SSP_COLORS_SUDO[@]}") ;;
|
|
862
|
+
\t\t"JJ") _SSP_EL_C=("${SSP_COLORS_JJ[@]}") ;;
|
|
863
|
+
\t\t"CUSTOM") _SSP_EL_C=("${SSP_COLORS_CUSTOM[@]}") ;;
|
|
864
|
+
\t\t"INPUT") _SSP_EL_C=("${SSP_COLORS_INPUT[@]}") ;;
|
|
865
|
+
\t\t*) _SSP_EL_C=(white none bold) ;;
|
|
866
|
+
\tesac
|
|
867
|
+
}"""
|
|
868
|
+
|
|
869
|
+
V12_COMBINE_ELEMENTS = """_ssp_text_for_el()
|
|
870
|
+
{
|
|
871
|
+
\tcase "${1:-}" in
|
|
872
|
+
\t\t"USER") _SSP_EL_TXT="${user:-}" ;;
|
|
873
|
+
\t\t"HOST") _SSP_EL_TXT="${host:-}" ;;
|
|
874
|
+
\t\t"PWD") _SSP_EL_TXT="${path:-}" ;;
|
|
875
|
+
\t\t"GIT") _SSP_EL_TXT="${git_branch:-}" ;;
|
|
876
|
+
\t\t"PYENV") _SSP_EL_TXT="${pyenv:-}" ;;
|
|
877
|
+
\t\t"KUBE") _SSP_EL_TXT="${kube:-}" ;;
|
|
878
|
+
\t\t"TF") _SSP_EL_TXT="${tf:-}" ;;
|
|
879
|
+
\t\t"CLOCK") _SSP_EL_TXT="${clock:-}" ;;
|
|
880
|
+
\t\t"STATUS") _SSP_EL_TXT="${status_seg:-}" ;;
|
|
881
|
+
\t\t"DURATION") _SSP_EL_TXT="${duration_seg:-}" ;;
|
|
882
|
+
\t\t"AWS") _SSP_EL_TXT="${aws_seg:-}" ;;
|
|
883
|
+
\t\t"GCP") _SSP_EL_TXT="${gcp_seg:-}" ;;
|
|
884
|
+
\t\t"DOCKER") _SSP_EL_TXT="${docker_seg:-}" ;;
|
|
885
|
+
\t\t"NODE") _SSP_EL_TXT="${node_seg:-}" ;;
|
|
886
|
+
\t\t"SSH") _SSP_EL_TXT="${ssh_seg:-}" ;;
|
|
887
|
+
\t\t"JOBS") _SSP_EL_TXT="${jobs_seg:-}" ;;
|
|
888
|
+
\t\t"DIRENV") _SSP_EL_TXT="${direnv_seg:-}" ;;
|
|
889
|
+
\t\t"SHLVL") _SSP_EL_TXT="${shlvl_seg:-}" ;;
|
|
890
|
+
\t\t"RUST") _SSP_EL_TXT="${rust_seg:-}" ;;
|
|
891
|
+
\t\t"GO") _SSP_EL_TXT="${go_seg:-}" ;;
|
|
892
|
+
\t\t"BATTERY") _SSP_EL_TXT="${battery_seg:-}" ;;
|
|
893
|
+
\t\t"SUDO") _SSP_EL_TXT="${sudo_seg:-}" ;;
|
|
894
|
+
\t\t"JJ") _SSP_EL_TXT="${jj_seg:-}" ;;
|
|
895
|
+
\t\t"CUSTOM") _SSP_EL_TXT="${custom_seg:-}" ;;
|
|
896
|
+
\t\t"INPUT") _SSP_EL_TXT="" ;;
|
|
897
|
+
\t\t*) _SSP_EL_TXT="" ;;
|
|
898
|
+
\tesac
|
|
899
|
+
}
|
|
900
|
+
_ssp_dyn_colors_var()
|
|
901
|
+
{
|
|
902
|
+
\t_ssp_colors_var "$1"
|
|
903
|
+
\tif [[ "$1" == "KUBE" && "${kube:-}" == *"🚨"* ]]; then
|
|
904
|
+
\t\t_SSP_EL_C=(white 196 "${_SSP_EL_C[2]:-bold}")
|
|
905
|
+
\telif [[ "$1" == "HOST" && -n "${_SSP_SSH_HOST_BG:-}" ]]; then
|
|
906
|
+
\t\t_SSP_EL_C=("${_SSP_SSH_HOST_FG:-white}" "${_SSP_SSH_HOST_BG}" "${_SSP_EL_C[2]:-bold}")
|
|
907
|
+
\telif [[ "$1" == "GIT" && "${SSP_GIT_DYNAMIC_COLOR:-false}" == "true" ]]; then
|
|
908
|
+
\t\tif [[ "${git_branch:-}" == *"| REBASE"* || "${git_branch:-}" == *"| MERGE"* || "${git_branch:-}" == *"| CHERRY"* || "${git_branch:-}" == *"| BISECT"* ]]; then
|
|
909
|
+
\t\t\t_SSP_EL_C=(white 196 "${_SSP_EL_C[2]:-bold}")
|
|
910
|
+
\t\telif [[ ( -n "${SSP_GIT_DIRTY:-}" && "${git_branch:-}" == *"${SSP_GIT_DIRTY}"* ) || "${git_branch:-}" == *"◔"* || "${git_branch:-}" == *"*"* ]]; then
|
|
911
|
+
\t\t\t_SSP_EL_C=(black 214 "${_SSP_EL_C[2]:-bold}")
|
|
912
|
+
\t\tfi
|
|
913
|
+
\tfi
|
|
914
|
+
}
|
|
915
|
+
_ssp_combine_var()
|
|
916
|
+
{
|
|
917
|
+
\tlocal first="${1:-}"
|
|
918
|
+
\tlocal second="${2:-}"
|
|
919
|
+
\t_ssp_dyn_colors_var "$first"
|
|
920
|
+
\tlocal text_color="${_SSP_EL_C[0]:-white}"
|
|
921
|
+
\tlocal bg_color="${_SSP_EL_C[1]:-none}"
|
|
922
|
+
\tlocal text_effect="${_SSP_EL_C[2]:-bold}"
|
|
923
|
+
\t_ssp_dyn_colors_var "$second"
|
|
924
|
+
\tlocal next_bg_color="${_SSP_EL_C[1]:-none}"
|
|
925
|
+
\t_ssp_text_for_el "$first"
|
|
926
|
+
\tlocal text="$_SSP_EL_TXT"
|
|
927
|
+
\tlocal sep_char="${separator_char:-}"
|
|
928
|
+
\tif [ "$second" = "INPUT" ] && [ -n "${separator_char_end:-}" ]; then
|
|
929
|
+
\t\tsep_char="$separator_char_end"
|
|
930
|
+
\tfi
|
|
931
|
+
\t_ssp_print_segment_var "$text" "$text_color" "$bg_color" "$next_bg_color" "$text_effect" "$sep_char"
|
|
932
|
+
}
|
|
933
|
+
combine_elements()
|
|
934
|
+
{
|
|
935
|
+
\t_ssp_combine_var "${1:-}" "${2:-}"
|
|
936
|
+
\tprintf '%s' "$_SSP_SEG_OUT"
|
|
937
|
+
}"""
|
|
938
|
+
|
|
939
|
+
V12_PROMPT_COMMAND_HOOK = """prompt_command_hook()
|
|
940
|
+
{
|
|
941
|
+
\tlocal last_exit=$?
|
|
942
|
+
\tlocal _ssp_had_u=0
|
|
943
|
+
\t[[ $- == *u* ]] && { _ssp_had_u=1; set +u; }
|
|
944
|
+
\t# synth-shell-theme: terminal_sanitize (auto-clear leaked SSH/TUI mouse tracking & focus reporting)
|
|
945
|
+
\tif [[ "${SSP_TERMINAL_SANITIZE:-true}" == "true" && -z "${BLE_VERSION:-}" ]] && [[ -t 1 || "${SSP_FORCE_SANITIZE:-}" == "1" ]]; then
|
|
946
|
+
\t\tprintf '\\e[?1000l\\e[?1002l\\e[?1003l\\e[?1006l\\e[?1015l\\e[?1004l'
|
|
947
|
+
\tfi
|
|
948
|
+
\tif [[ "${SSP_ENABLE_OSC7:-true}" == "true" ]] && [[ -t 1 || "${SSP_FORCE_OSC7:-}" == "1" ]]; then
|
|
949
|
+
\t\t_ssp_osc7_emit
|
|
950
|
+
\tfi
|
|
951
|
+
\t_ssp_host_color_var
|
|
952
|
+
\tlocal elements=("${SSP_ELEMENTS[@]}")
|
|
953
|
+
\tlocal right_elements=("${SSP_RIGHT_ELEMENTS[@]}")
|
|
954
|
+
\tlocal user="${USER:-}"
|
|
955
|
+
\tlocal host="${HOSTNAME:-}"
|
|
956
|
+
\tlocal _is_compact=0
|
|
957
|
+
\tlocal _cw="${SSP_COMPACT_WIDTH:-90}"
|
|
958
|
+
\tif (( _cw > 0 && ${COLUMNS:-120} > 0 && ${COLUMNS:-120} < _cw )); then
|
|
959
|
+
\t\t_is_compact=1
|
|
960
|
+
\tfi
|
|
961
|
+
\tlocal _eff_pwd_max="${SSP_MAX_PWD_CHAR:-35}"
|
|
962
|
+
\tif (( _is_compact == 1 && _eff_pwd_max > 18 )); then
|
|
963
|
+
\t\t_eff_pwd_max=18
|
|
964
|
+
\tfi
|
|
965
|
+
\tlocal path="" git_branch="" pyenv="" kube="" tf="" clock=""
|
|
966
|
+
\tlocal status_seg="" duration_seg="" aws_seg="" gcp_seg="" docker_seg="" node_seg="" ssh_seg=""
|
|
967
|
+
\tlocal jobs_seg="" direnv_seg="" shlvl_seg="" rust_seg="" go_seg="" battery_seg=""
|
|
968
|
+
\tlocal sudo_seg="" jj_seg="" custom_seg=""
|
|
969
|
+
|
|
970
|
+
\tif _ssp_has_element "PWD"; then
|
|
971
|
+
\t\tif [[ "${SSP_PWD_STYLE:-default}" == "fish" ]]; then
|
|
972
|
+
\t\t\t_ssp_shorten_path_fish "$PWD"
|
|
973
|
+
\t\t\tpath="$_SSP_FISH_PATH"
|
|
974
|
+
\t\telse
|
|
975
|
+
\t\t\tpath="$(shortenPath "$PWD" "$_eff_pwd_max" "${SSP_PWD_TRUNC_SYMBOL:-…}")"
|
|
976
|
+
\t\tfi
|
|
977
|
+
\tfi
|
|
978
|
+
\t_ssp_has_element "GIT" && git_branch="$(getGitBranch)"
|
|
979
|
+
\t_ssp_has_element "JJ" && jj_seg="$(getJj)"
|
|
980
|
+
\t_ssp_has_element "PYENV" && pyenv="$(getPyenv)"
|
|
981
|
+
\tif (( _is_compact == 0 )); then
|
|
982
|
+
\t\t_ssp_has_element "KUBE" && kube="$(getKube)"
|
|
983
|
+
\t\t_ssp_has_element "TF" && tf="$(getTerraform)"
|
|
984
|
+
\t\tif _ssp_has_element "CLOCK"; then
|
|
985
|
+
\t\t\tprintf -v clock "%(${SSP_CLOCK_FORMAT:-%H:%M})T" -1 2>/dev/null || clock="$(date +"${SSP_CLOCK_FORMAT:-%H:%M}")"
|
|
986
|
+
\t\tfi
|
|
987
|
+
\t\t_ssp_has_element "AWS" && aws_seg="$(getAws)"
|
|
988
|
+
\t\t_ssp_has_element "GCP" && gcp_seg="$(getGcp)"
|
|
989
|
+
\t\t_ssp_has_element "DOCKER" && docker_seg="$(getDocker)"
|
|
990
|
+
\t\t_ssp_has_element "NODE" && node_seg="$(getNode)"
|
|
991
|
+
\t\t_ssp_has_element "RUST" && rust_seg="$(getRust)"
|
|
992
|
+
\t\t_ssp_has_element "GO" && go_seg="$(getGo)"
|
|
993
|
+
\t\t_ssp_has_element "BATTERY" && battery_seg="$(getBattery)"
|
|
994
|
+
\tfi
|
|
995
|
+
\tif _ssp_has_element "STATUS" && (( last_exit != 0 )); then
|
|
996
|
+
\t\tstatus_seg="${SSP_STATUS_SYMBOL:-✗ }${last_exit}"
|
|
997
|
+
\tfi
|
|
998
|
+
\t_SSP_LAST_ELAPSED_MS=0
|
|
999
|
+
\tif _ssp_has_element "DURATION" || (( ${SSP_NOTIFY_DURATION_SEC:-0} > 0 )); then
|
|
1000
|
+
\t\t_ssp_format_duration_var
|
|
1001
|
+
\t\t_ssp_has_element "DURATION" && duration_seg="$_SSP_DUR"
|
|
1002
|
+
\tfi
|
|
1003
|
+
\tif (( ${SSP_NOTIFY_DURATION_SEC:-0} > 0 && _SSP_LAST_ELAPSED_MS >= SSP_NOTIFY_DURATION_SEC * 1000 )) && [[ -t 1 || "${SSP_FORCE_NOTIFY:-}" == "1" ]]; then
|
|
1004
|
+
\t\tlocal _n_msg=""
|
|
1005
|
+
\t\tif (( last_exit == 0 )); then
|
|
1006
|
+
\t\t\tprintf -v _n_msg 'synth-shell: ✓ Command finished (%d.%ds)' $(( _SSP_LAST_ELAPSED_MS / 1000 )) $(( (_SSP_LAST_ELAPSED_MS % 1000) / 100 ))
|
|
1007
|
+
\t\telse
|
|
1008
|
+
\t\t\tprintf -v _n_msg 'synth-shell: ✗ Command failed (exit %d, %d.%ds)' "$last_exit" $(( _SSP_LAST_ELAPSED_MS / 1000 )) $(( (_SSP_LAST_ELAPSED_MS % 1000) / 100 ))
|
|
1009
|
+
\t\tfi
|
|
1010
|
+
\t\tcase "${TERM:-}" in
|
|
1011
|
+
\t\t\t*kitty*) printf '\\e]99;i=1:d=0;%s\\a' "$_n_msg" ;;
|
|
1012
|
+
\t\t\t*) printf '\\e]9;%s\\a' "$_n_msg" ;;
|
|
1013
|
+
\t\tesac
|
|
1014
|
+
\tfi
|
|
1015
|
+
\t_SSP_CMD_START_MS=0
|
|
1016
|
+
\t_ssp_has_element "SSH" && ssh_seg="$(getSsh)"
|
|
1017
|
+
\t_ssp_has_element "JOBS" && jobs_seg="$(getJobs)"
|
|
1018
|
+
\t_ssp_has_element "DIRENV" && direnv_seg="$(getDirenv)"
|
|
1019
|
+
\t_ssp_has_element "SHLVL" && shlvl_seg="$(getShlvl)"
|
|
1020
|
+
\t_ssp_has_element "SUDO" && sudo_seg="$(getSudo)"
|
|
1021
|
+
\t_ssp_has_element "CUSTOM" && custom_seg="$(getCustom)"
|
|
1022
|
+
|
|
1023
|
+
\tlocal filtered=() _el
|
|
1024
|
+
\tfor _el in "${elements[@]}"; do
|
|
1025
|
+
\t\t_ssp_text_for_el "$_el"
|
|
1026
|
+
\t\tif [[ "$_el" == "INPUT" || -n "$_SSP_EL_TXT" ]]; then
|
|
1027
|
+
\t\t\tfiltered+=("$_el")
|
|
1028
|
+
\t\tfi
|
|
1029
|
+
\tdone
|
|
1030
|
+
\telements=("${filtered[@]}")
|
|
1031
|
+
|
|
1032
|
+
\tlocal r_filtered=()
|
|
1033
|
+
\tif (( _is_compact == 0 && ${#right_elements[@]} > 0 )) && [[ -n "${SSP_PROMPT_COMM_SEP:-}" ]]; then
|
|
1034
|
+
\t\tfor _el in "${right_elements[@]}"; do
|
|
1035
|
+
\t\t\t_ssp_text_for_el "$_el"
|
|
1036
|
+
\t\t\t[[ -n "$_SSP_EL_TXT" ]] && r_filtered+=("$_el")
|
|
1037
|
+
\t\tdone
|
|
1038
|
+
\tfi
|
|
1039
|
+
|
|
1040
|
+
\tlocal titlebar=""
|
|
1041
|
+
\tif [[ "${SSP_ENABLE_TERMINAL_TITLE:-true}" == "true" ]]; then
|
|
1042
|
+
\t\tcase "${TERM:-}" in
|
|
1043
|
+
\t\t\txterm*|rxvt*|screen*|tmux*|alacritty*|kitty*|foot*|wezterm*|ghostty*)
|
|
1044
|
+
\t\t\t\tSSP_PWD="$path"
|
|
1045
|
+
\t\t\t\ttitlebar="\\[\\e]0;\\u@\\h: \\w\\a\\]"
|
|
1046
|
+
\t\t\t\t;;
|
|
1047
|
+
\t\tesac
|
|
1048
|
+
\tfi
|
|
1049
|
+
|
|
1050
|
+
\tlocal osc_pre="" osc_post=""
|
|
1051
|
+
\tif [[ "${SSP_ENABLE_OSC133:-true}" == "true" ]]; then
|
|
1052
|
+
\t\tif (( ${_SSP_HAS_RUN:-0} == 1 )); then
|
|
1053
|
+
\t\t\tosc_pre="\\[\\e]133;D;${last_exit}\\a\\]\\[\\e]133;A\\a\\]"
|
|
1054
|
+
\t\telse
|
|
1055
|
+
\t\t\tosc_pre="\\[\\e]133;A\\a\\]"
|
|
1056
|
+
\t\tfi
|
|
1057
|
+
\t\tosc_post="\\[\\e]133;B\\a\\]"
|
|
1058
|
+
\t\t_SSP_HAS_RUN=1
|
|
1059
|
+
\tfi
|
|
1060
|
+
|
|
1061
|
+
\tPS1="${osc_pre}${titlebar}${SSP_VERTICAL_PADDING:-}${SSP_NEW_LINE_LINK_TOP:-}${SSP_PROMPT_PREFIX:-}"
|
|
1062
|
+
\tlocal _top_s="${SSP_NEW_LINE_LINK_TOP:-}" _pre_s="${SSP_PROMPT_PREFIX:-}" _pad_s="${segment_padding:- }"
|
|
1063
|
+
\tlocal left_vis=$(( ${#_top_s} + ${#_pre_s} ))
|
|
1064
|
+
\tlocal pad_w=$(( ${#_pad_s} * 2 + 1 ))
|
|
1065
|
+
\tlocal idx=0 total="${#elements[@]}"
|
|
1066
|
+
\twhile (( idx + 1 < total )); do
|
|
1067
|
+
\t\t_ssp_text_for_el "${elements[$idx]}"
|
|
1068
|
+
\t\tleft_vis=$(( left_vis + ${#_SSP_EL_TXT} + pad_w ))
|
|
1069
|
+
\t\t_ssp_combine_var "${elements[$idx]}" "${elements[$((idx + 1))]}"
|
|
1070
|
+
\t\tPS1+="$_SSP_SEG_OUT"
|
|
1071
|
+
\t\tidx=$((idx + 1))
|
|
1072
|
+
\tdone
|
|
1073
|
+
|
|
1074
|
+
\tif (( ${#r_filtered[@]} > 0 )); then
|
|
1075
|
+
\t\tlocal right_str="" right_vis=0 r_idx=0 r_tot="${#r_filtered[@]}"
|
|
1076
|
+
\t\twhile (( r_idx < r_tot )); do
|
|
1077
|
+
\t\t\tlocal r_cur="${r_filtered[$r_idx]}"
|
|
1078
|
+
\t\t\tlocal r_nxt="INPUT"
|
|
1079
|
+
\t\t\t(( r_idx + 1 < r_tot )) && r_nxt="${r_filtered[$((r_idx + 1))]}"
|
|
1080
|
+
\t\t\t_ssp_text_for_el "$r_cur"
|
|
1081
|
+
\t\t\tright_vis=$(( right_vis + ${#_SSP_EL_TXT} + pad_w ))
|
|
1082
|
+
\t\t\t_ssp_combine_var "$r_cur" "$r_nxt"
|
|
1083
|
+
\t\t\tright_str+="$_SSP_SEG_OUT"
|
|
1084
|
+
\t\t\tr_idx=$((r_idx + 1))
|
|
1085
|
+
\t\tdone
|
|
1086
|
+
\t\tlocal fill_len=$(( ${COLUMNS:-120} - left_vis - right_vis - 2 ))
|
|
1087
|
+
\t\tif (( fill_len >= 2 )); then
|
|
1088
|
+
\t\t\tlocal fill_ch="${SSP_RIGHT_FILL_CHAR:-─}"
|
|
1089
|
+
\t\t\tlocal fill_spaces=""
|
|
1090
|
+
\t\t\tprintf -v fill_spaces '%*s' "$fill_len" ""
|
|
1091
|
+
\t\t\tlocal fill_line="${fill_spaces// /$fill_ch}"
|
|
1092
|
+
\t\t\tPS1+=" \\[\\e[0;38;5;239m\\]${fill_line}\\[\\e[0;0m\\] ${right_str}"
|
|
1093
|
+
\t\tfi
|
|
1094
|
+
\tfi
|
|
1095
|
+
|
|
1096
|
+
\t_ssp_colors_var "${elements[$idx]}"
|
|
1097
|
+
\tlocal input_color="${_SSP_EL_C[0]:-white}"
|
|
1098
|
+
\tlocal input_bg="${_SSP_EL_C[1]:-none}"
|
|
1099
|
+
\tlocal input_effect="${_SSP_EL_C[2]:-bold}"
|
|
1100
|
+
\t_ssp_fmt_var "$input_color" "$input_bg" "$input_effect"
|
|
1101
|
+
\tlocal input_format="$_SSP_FMT"
|
|
1102
|
+
\tlocal command_start_symbol="${input_format}${SSP_BASH_SYMBOL:-}"
|
|
1103
|
+
\tPS1="${PS1}${SSP_PROMPT_COMM_SEP:-}${SSP_NEW_LINE_LINK_BOTTOM:-}${command_start_symbol} ${input_format}${osc_post}"
|
|
1104
|
+
\tif (( _ssp_had_u )); then set -u; fi
|
|
1105
|
+
}"""
|
|
1106
|
+
|
|
1107
|
+
V12_INIT_AND_CHAINING = """\t# synth-shell-theme: v11_init
|
|
1108
|
+
\t# synth-shell-theme: v12_init
|
|
1109
|
+
\t# synth-shell-theme: v13_init
|
|
1110
|
+
\t# synth-shell-theme: v139_init
|
|
1111
|
+
\t# synth-shell-theme: hook_chaining
|
|
1112
|
+
\tSSP_RIGHT_ELEMENTS=(${right_format:-})
|
|
1113
|
+
\tSSP_RIGHT_FILL_CHAR="${right_fill_char:-─}"
|
|
1114
|
+
\tSSP_ENABLE_OSC133=${enable_osc133:-true}
|
|
1115
|
+
\tSSP_ENABLE_OSC7=${enable_osc7:-true}
|
|
1116
|
+
\tSSP_TERMINAL_SANITIZE=${enable_terminal_sanitize:-true}
|
|
1117
|
+
\tSSP_KUBE_SHOW_NAMESPACE=${kube_show_namespace:-true}
|
|
1118
|
+
\tSSP_KUBE_PROD_WARNING=${kube_prod_warning:-true}
|
|
1119
|
+
\tSSP_KUBE_PROD_PATTERN="${kube_prod_pattern:-prod|production|prd|live}"
|
|
1120
|
+
\tSSP_GIT_DYNAMIC_COLOR=${git_dynamic_color:-false}
|
|
1121
|
+
\tSSP_SSH_HOST_COLOR=${ssh_host_color:-false}
|
|
1122
|
+
\tSSP_PWD_STYLE="${pwd_style:-default}"
|
|
1123
|
+
\tSSP_NOTIFY_DURATION_SEC=${notify_duration_sec:-0}
|
|
1124
|
+
\tSSP_CUSTOM_TEXT="${custom_segment_text:-}"
|
|
1125
|
+
\tSSP_SUDO_SYMBOL="${sudo_symbol:-🔓 sudo}"
|
|
1126
|
+
\tSSP_GIT_SHOW_STATE=${git_show_state:-true}
|
|
1127
|
+
\tSSP_BATTERY_THRESHOLD=${battery_threshold:-100}
|
|
1128
|
+
\tSSP_COLORS_STATUS=(${font_color_status:-white} ${background_status:-196} ${texteffect_status:-bold})
|
|
1129
|
+
\tSSP_COLORS_DURATION=(${font_color_duration:-black} ${background_duration:-220} ${texteffect_duration:-bold})
|
|
1130
|
+
\tSSP_COLORS_AWS=(${font_color_aws:-black} ${background_aws:-208} ${texteffect_aws:-bold})
|
|
1131
|
+
\tSSP_COLORS_GCP=(${font_color_gcp:-white} ${background_gcp:-33} ${texteffect_gcp:-bold})
|
|
1132
|
+
\tSSP_COLORS_DOCKER=(${font_color_docker:-white} ${background_docker:-39} ${texteffect_docker:-bold})
|
|
1133
|
+
\tSSP_COLORS_NODE=(${font_color_node:-black} ${background_node:-76} ${texteffect_node:-bold})
|
|
1134
|
+
\tSSP_COLORS_SSH=(${font_color_ssh:-white} ${background_ssh:-125} ${texteffect_ssh:-bold})
|
|
1135
|
+
\tSSP_COLORS_JOBS=(${font_color_jobs:-black} ${background_jobs:-214} ${texteffect_jobs:-bold})
|
|
1136
|
+
\tSSP_COLORS_DIRENV=(${font_color_direnv:-black} ${background_direnv:-114} ${texteffect_direnv:-bold})
|
|
1137
|
+
\tSSP_COLORS_SHLVL=(${font_color_shlvl:-white} ${background_shlvl:-99} ${texteffect_shlvl:-bold})
|
|
1138
|
+
\tSSP_COLORS_RUST=(${font_color_rust:-white} ${background_rust:-166} ${texteffect_rust:-bold})
|
|
1139
|
+
\tSSP_COLORS_GO=(${font_color_go:-black} ${background_go:-81} ${texteffect_go:-bold})
|
|
1140
|
+
\tSSP_COLORS_BATTERY=(${font_color_battery:-black} ${background_battery:-114} ${texteffect_battery:-bold})
|
|
1141
|
+
\tSSP_COLORS_SUDO=(${font_color_sudo:-white} ${background_sudo:-196} ${texteffect_sudo:-bold})
|
|
1142
|
+
\tSSP_COLORS_JJ=(${font_color_jj:-black} ${background_jj:-214} ${texteffect_jj:-bold})
|
|
1143
|
+
\tSSP_COLORS_CUSTOM=(${font_color_custom:-black} ${background_custom:-219} ${texteffect_custom:-bold})
|
|
1144
|
+
\tSSP_MAX_GIT_CHAR=${max_git_char:-0}
|
|
1145
|
+
\tSSP_MAX_PYENV_CHAR=${max_pyenv_char:-0}
|
|
1146
|
+
\tSSP_MAX_KUBE_CHAR=${max_kube_char:-28}
|
|
1147
|
+
\tSSP_COMPACT_WIDTH=${compact_width:-90}
|
|
1148
|
+
\tSSP_GIT_SHOW_COUNTS=${git_show_counts:-true}
|
|
1149
|
+
\tSSP_GIT_SKIP_UNTRACKED_ON_SLOW_FS=${git_skip_untracked_on_slow_fs:-true}
|
|
1150
|
+
\tSSP_GIT_TIMEOUT_MS=${git_timeout_ms:-0}
|
|
1151
|
+
\tSSP_GIT_ASYNC_CACHE=${git_async_cache:-false}
|
|
1152
|
+
\tSSP_MIN_DURATION_MS=${min_duration_ms:-2000}
|
|
1153
|
+
\tSSP_ENABLE_TERMINAL_TITLE=${enable_terminal_title:-true}
|
|
1154
|
+
\tSSP_FONT_EFFECT_OVERRIDE="${font_effect_override:-}"
|
|
1155
|
+
\tSSP_STATUS_SYMBOL="${status_symbol:-✗ }"
|
|
1156
|
+
\tSSP_TRANSIENT_PROMPT=${transient_prompt:-false}
|
|
1157
|
+
\tif [[ "${prompt_prefix:-}" == "auto" ]]; then
|
|
1158
|
+
\t\t_ssp_auto_os_icon
|
|
1159
|
+
\t\tSSP_PROMPT_PREFIX="$_SSP_PREFIX"
|
|
1160
|
+
\telse
|
|
1161
|
+
\t\tSSP_PROMPT_PREFIX="${prompt_prefix:-}"
|
|
1162
|
+
\tfi
|
|
1163
|
+
\t_ssp_resolve_sep "${separator_char:-\\uE0B0}"
|
|
1164
|
+
\tseparator_char="$_SSP_SEP"
|
|
1165
|
+
\tif [[ -n "${separator_char_end:-}" ]]; then
|
|
1166
|
+
\t\t_ssp_resolve_sep "${separator_char_end}"
|
|
1167
|
+
\t\tseparator_char_end="$_SSP_SEP"
|
|
1168
|
+
\tfi
|
|
1169
|
+
\t_SSP_EMPTY=""
|
|
1170
|
+
\t_SSP_CMD_START_MS=0
|
|
1171
|
+
\t_SSP_HAS_RUN=0
|
|
1172
|
+
\tlocal _ps0_osc=""
|
|
1173
|
+
\t[[ "${SSP_ENABLE_OSC133}" == "true" ]] && _ps0_osc=$'\\e]133;C\\a'
|
|
1174
|
+
\tif [[ -n "${EPOCHREALTIME:-}" ]]; then
|
|
1175
|
+
\t\tPS0="${_ps0_osc}"$'\\e[0m''${_SSP_EMPTY:0:((_SSP_CMD_START_MS=${EPOCHREALTIME/./}/1000, 0))}'
|
|
1176
|
+
\telse
|
|
1177
|
+
\t\tPS0="${_ps0_osc}"$'\\e[0m''${_SSP_EMPTY:0:((_SSP_CMD_START_MS=SECONDS*1000, 0))}'
|
|
1178
|
+
\tfi
|
|
1179
|
+
\tif [[ "${SSP_TRANSIENT_PROMPT}" == "true" && -n "${BLE_VERSION:-}" ]] && command -v bleopt >/dev/null 2>&1; then
|
|
1180
|
+
\t\tbleopt prompt_ps1_transient=trim 2>/dev/null || true
|
|
1181
|
+
\tfi
|
|
1182
|
+
\tif declare -p PROMPT_COMMAND 2>/dev/null | grep -q 'declare -a'; then
|
|
1183
|
+
\t\tlocal _ssp_pc_has=0 _ssp_pc_item
|
|
1184
|
+
\t\tfor _ssp_pc_item in "${PROMPT_COMMAND[@]}"; do
|
|
1185
|
+
\t\t\t[[ "$_ssp_pc_item" == "prompt_command_hook" ]] && _ssp_pc_has=1 && break
|
|
1186
|
+
\t\tdone
|
|
1187
|
+
\t\t(( _ssp_pc_has == 0 )) && PROMPT_COMMAND=(prompt_command_hook "${PROMPT_COMMAND[@]}")
|
|
1188
|
+
\telse
|
|
1189
|
+
\t\tcase ";${PROMPT_COMMAND:-};" in
|
|
1190
|
+
\t\t\t*";prompt_command_hook;"*) ;;
|
|
1191
|
+
\t\t\t";;") PROMPT_COMMAND="prompt_command_hook" ;;
|
|
1192
|
+
\t\t\t*) PROMPT_COMMAND="prompt_command_hook;${PROMPT_COMMAND}" ;;
|
|
1193
|
+
\t\tesac
|
|
1194
|
+
\tfi"""
|
|
1195
|
+
|
|
1196
|
+
PATCHED_GREETER_AMD_TEMP = """printInfoCPUTemp()
|
|
1197
|
+
{
|
|
1198
|
+
\t# synth-shell-theme: greeter_amd_temp (LC_ALL=C + AMD k10temp/Tctl/Tdie support)
|
|
1199
|
+
\tif command -v sensors >/dev/null 2>&1; then
|
|
1200
|
+
\t\tlocal temp_line
|
|
1201
|
+
\t\ttemp_line="$(LC_ALL=C sensors 2>/dev/null | grep -E '^(Core 0|Package id 0|Tctl|Tdie|CPU|temp1):' | head -n 1 | sed 's/^.*:[ \\t]*//g;s/[\\(\\),]//g')"
|
|
1202
|
+
\t\tif [[ -z "$temp_line" ]]; then
|
|
1203
|
+
\t\t\tprintInfoLine "CPU temp" "unavailable"
|
|
1204
|
+
\t\t\treturn
|
|
1205
|
+
\t\tfi
|
|
1206
|
+
\t\tlocal current=""
|
|
1207
|
+
\t\tif [[ "$temp_line" =~ \\+?([0-9]+(\\.[0-9]+)?) ]]; then
|
|
1208
|
+
\t\t\tcurrent="${BASH_REMATCH[1]}"
|
|
1209
|
+
\t\tfi
|
|
1210
|
+
\t\tif [[ -z "$current" ]]; then
|
|
1211
|
+
\t\t\tprintInfoLine "CPU temp" "unavailable"
|
|
1212
|
+
\t\t\treturn
|
|
1213
|
+
\t\tfi
|
|
1214
|
+
\t\tlocal high=75 max=90
|
|
1215
|
+
\t\t[[ "$temp_line" =~ high[[:space:]]*=[[:space:]]*\\+?([0-9]+(\\.[0-9]+)?) ]] && high="${BASH_REMATCH[1]}"
|
|
1216
|
+
\t\t[[ "$temp_line" =~ crit[[:space:]]*=[[:space:]]*\\+?([0-9]+(\\.[0-9]+)?) ]] && max="${BASH_REMATCH[1]}"
|
|
1217
|
+
\t\tlocal cur_int="${current%%.*}" high_int="${high%%.*}" max_int="${max%%.*}"
|
|
1218
|
+
\t\tlocal state="nominal"
|
|
1219
|
+
\t\tif (( cur_int >= max_int )); then
|
|
1220
|
+
\t\t\tstate="error"
|
|
1221
|
+
\t\telif (( cur_int >= high_int )); then
|
|
1222
|
+
\t\t\tstate="critical"
|
|
1223
|
+
\t\tfi
|
|
1224
|
+
\t\tprintInfoLine "CPU temp" "${current}°C" "$state"
|
|
1225
|
+
\telse
|
|
1226
|
+
\t\tprintInfoLine "CPU temp" "lm-sensors not installed"
|
|
1227
|
+
\tfi
|
|
1228
|
+
}"""
|
|
1229
|
+
|
|
1230
|
+
PATCHED_GREETER_ZFS_RAM = """printMonitorRAM()
|
|
1231
|
+
{
|
|
1232
|
+
\t# synth-shell-theme: greeter_zfs_arc (accounts for reclaimable ZFS ARC memory)
|
|
1233
|
+
\tassert_is_set $bar_ram_units
|
|
1234
|
+
\tassert_is_set $bar_ram_crit_percent
|
|
1235
|
+
\tlocal format=$1
|
|
1236
|
+
\tlocal label="Memory"
|
|
1237
|
+
\tlocal units="GB" option="--giga" div=1073741824
|
|
1238
|
+
\tcase "$bar_ram_units" in
|
|
1239
|
+
\t\t"MB") units="MB"; option="--mega"; div=1048576 ;;
|
|
1240
|
+
\t\t"TB") units="TB"; option="--tera"; div=1099511627776 ;;
|
|
1241
|
+
\t\t"PB") units="PB"; option="--peta"; div=1125899906842624 ;;
|
|
1242
|
+
\tesac
|
|
1243
|
+
\tlocal mem_info
|
|
1244
|
+
\tmem_info=$('free' "$option" | head -n 2 | tail -n 1)
|
|
1245
|
+
\tlocal current_value
|
|
1246
|
+
\tcurrent_value=$(echo "$mem_info" | awk '{mem=($2-$7)} END {printf mem}')
|
|
1247
|
+
\tlocal max
|
|
1248
|
+
\tmax=$(echo "$mem_info" | awk '{mem=($2)} END {printf mem}')
|
|
1249
|
+
\tif [[ -r /proc/spl/kstat/zfs/arcstats ]]; then
|
|
1250
|
+
\t\tlocal arc_size=0 arc_cmin=0 _k _t _v
|
|
1251
|
+
\t\twhile read -r _k _t _v; do
|
|
1252
|
+
\t\t\t[[ "$_k" == "size" ]] && arc_size="$_v"
|
|
1253
|
+
\t\t\t[[ "$_k" == "c_min" ]] && arc_cmin="$_v"
|
|
1254
|
+
\t\tdone < /proc/spl/kstat/zfs/arcstats
|
|
1255
|
+
\t\tif (( arc_size > arc_cmin )); then
|
|
1256
|
+
\t\t\tlocal reclaim=$(( (arc_size - arc_cmin) / div ))
|
|
1257
|
+
\t\t\tif (( current_value > reclaim )); then
|
|
1258
|
+
\t\t\t\tcurrent_value=$(( current_value - reclaim ))
|
|
1259
|
+
\t\t\tfi
|
|
1260
|
+
\t\tfi
|
|
1261
|
+
\tfi
|
|
1262
|
+
\tlocal crit_percent=$bar_ram_crit_percent
|
|
1263
|
+
\tprintResourceMonitor "$label" "$current_value" "$max" "$units" "$format" "$crit_percent"
|
|
1264
|
+
}"""
|
|
1265
|
+
|
|
1266
|
+
def _fn_re(name: str) -> re.Pattern[str]:
|
|
1267
|
+
return re.compile(rf"^{name}\(\)\s*\{{(?:[^\n]*\}}|.*?\n\}})", re.MULTILINE | re.DOTALL)
|
|
1268
|
+
|
|
1269
|
+
|
|
1270
|
+
_GET_KUBE_RE = _fn_re("getKube")
|
|
1271
|
+
_GET_PYENV_RE = _fn_re("getPyenv")
|
|
1272
|
+
_PRINT_SEG_FULL_RE = _fn_re("printSegment")
|
|
1273
|
+
_ZERO_FORK_BLOCK_RE = re.compile(
|
|
1274
|
+
r"^# synth-shell-theme: zero_fork_render\n.*?^_ssp_print_segment_var\(\)\s*\{.*?\n\}",
|
|
1275
|
+
re.MULTILINE | re.DOTALL,
|
|
1276
|
+
)
|
|
1277
|
+
_V11_SEGS_BLOCK_RE = re.compile(
|
|
1278
|
+
r"^# synth-shell-theme: v11_segments\n.*?^_ssp_colors_var\(\)\s*\{.*?\n\}",
|
|
1279
|
+
re.MULTILINE | re.DOTALL,
|
|
1280
|
+
)
|
|
1281
|
+
_GET_COLORS_RE = _fn_re("get_colors_for_element")
|
|
1282
|
+
_COMBINE_V11_RE = re.compile(
|
|
1283
|
+
r"^(?:_ssp_text_for_el\(\)\s*\{.*?\n\}\n)?_ssp_combine_var\(\)\s*\{.*?\n\}\ncombine_elements\(\)\s*\{.*?\n\}",
|
|
1284
|
+
re.MULTILINE | re.DOTALL,
|
|
1285
|
+
)
|
|
1286
|
+
_COMBINE_FULL_RE = _fn_re("combine_elements")
|
|
1287
|
+
_PROMPT_HOOK_RE = _fn_re("prompt_command_hook")
|
|
1288
|
+
_GET_EFFECT_RE = _fn_re("getEffectCode")
|
|
1289
|
+
_V11_INIT_AND_PC_RE = re.compile(
|
|
1290
|
+
r"^\t# synth-shell-theme: v11_init\n.*?(?:\tPROMPT_COMMAND=prompt_command_hook|\t\tesac\n\tfi)",
|
|
1291
|
+
re.MULTILINE | re.DOTALL,
|
|
1292
|
+
)
|
|
1293
|
+
_V12_GIT_RE = re.compile(
|
|
1294
|
+
r"^[ \t]*# synth-shell-theme: git_single_pass v12[^\n]*\n.*?"
|
|
1295
|
+
r"[ \t]*\[\[ -n \"\$_ab_counts\" \]\] && branch=\"\$\{branch\}\$\{_ab_counts\}\"\n[ \t]*fi",
|
|
1296
|
+
re.MULTILINE | re.DOTALL,
|
|
1297
|
+
)
|
|
1298
|
+
_DEBUG_TRAP_RE = re.compile(
|
|
1299
|
+
r"^[ \t]*none=\"\$\(tput sgr0\)\"\n[ \t]*trap 'echo -ne \"\$\{none\}\"' DEBUG\n",
|
|
1300
|
+
re.MULTILINE,
|
|
1301
|
+
)
|
|
1302
|
+
|
|
1303
|
+
_OLD_GIT_RE = re.compile(
|
|
1304
|
+
r"^[ \t]*local is_dirty=false &&\\\n"
|
|
1305
|
+
r"[ \t]*\[\[ -n \"\$\(git status --porcelain\)\" \]\] &&\\\n"
|
|
1306
|
+
r"[ \t]*is_dirty=true\n"
|
|
1307
|
+
r"[ \t]*local is_ahead=false &&\\\n"
|
|
1308
|
+
r"[ \t]*\[\[ \"\$\(git status --porcelain -u no -b\)\" == \*\"ahead\"\* \]\] &&\\\n"
|
|
1309
|
+
r"[ \t]*is_ahead=true\n"
|
|
1310
|
+
r"[ \t]*local is_behind=false &&\\\n"
|
|
1311
|
+
r"[ \t]*\[\[ \"\$\(git status --porcelain -u no -b\)\" == \*\"behind\"\* \]\] &&\\\n"
|
|
1312
|
+
r"[ \t]*is_behind=true",
|
|
1313
|
+
re.MULTILINE,
|
|
1314
|
+
)
|
|
1315
|
+
|
|
1316
|
+
_V10_GIT_RE = re.compile(
|
|
1317
|
+
r"^[ \t]*# synth-shell-theme: git_single_pass\n"
|
|
1318
|
+
r"[ \t]*local status_out=\"\$\(git status --porcelain -b 2>/dev/null\)\"\n"
|
|
1319
|
+
r"[ \t]*local is_dirty=false\n"
|
|
1320
|
+
r"[ \t]*\[\[ \"\$status_out\" =~ \$'\\n' \]\] && is_dirty=true\n"
|
|
1321
|
+
r"[ \t]*local branch_line=\"\$\{status_out%%\$'\\n'\*\}\"\n"
|
|
1322
|
+
r"[ \t]*local is_ahead=false && \[\[ \"\$branch_line\" == \*\"ahead\"\* \]\] && is_ahead=true\n"
|
|
1323
|
+
r"[ \t]*local is_behind=false && \[\[ \"\$branch_line\" == \*\"behind\"\* \]\] && is_behind=true",
|
|
1324
|
+
re.MULTILINE,
|
|
1325
|
+
)
|
|
1326
|
+
|
|
1327
|
+
_V11_GIT_RE = re.compile(
|
|
1328
|
+
r"^[ \t]*# synth-shell-theme: git_single_pass v11[^\n]*\n.*?"
|
|
1329
|
+
r"[ \t]*branch=\"\$\{branch:0:\$\(\(_max_g - 1\)\)\}…\"\n[ \t]*fi",
|
|
1330
|
+
re.MULTILINE | re.DOTALL,
|
|
1331
|
+
)
|
|
1332
|
+
|
|
1333
|
+
_COMBINE_TAIL_RE = re.compile(
|
|
1334
|
+
r"(\tlocal text_effect=\$\{colors_first\[2\]\}\n)"
|
|
1335
|
+
r"\tprintSegment \"\$text\" \"\$text_color\" \"\$bg_color\" \"\$next_bg_color\" \"\$text_effect\"(\s*\n\})",
|
|
1336
|
+
re.MULTILINE,
|
|
1337
|
+
)
|
|
1338
|
+
|
|
1339
|
+
_COLOR_BLOCK_RE = re.compile(
|
|
1340
|
+
r"^getColorCode\(\)\s*\{.*?^\}\s*(?:##[^\n]*\n\s*)*^getBackgroundCode\(\)\s*\{.*?^\}",
|
|
1341
|
+
re.MULTILINE | re.DOTALL,
|
|
1342
|
+
)
|
|
1343
|
+
|
|
1344
|
+
_GREETER_TEMP_RE = re.compile(r"^printInfoCPUTemp\(\)\s*\{.*?\n\}", re.MULTILINE | re.DOTALL)
|
|
1345
|
+
_GREETER_RAM_RE = re.compile(r"^printMonitorRAM\(\)\s*\{.*?\n\}", re.MULTILINE | re.DOTALL)
|
|
1346
|
+
|
|
1347
|
+
|
|
1348
|
+
def _backup_script_once(script_path: Path, backup_dir: Path) -> None:
|
|
1349
|
+
"""Create an initial `.orig.bak` backup of a shell script before first patching."""
|
|
1350
|
+
backup_dir.mkdir(parents=True, exist_ok=True)
|
|
1351
|
+
orig_bak = backup_dir / f"{script_path.name}.orig.bak"
|
|
1352
|
+
if not orig_bak.exists():
|
|
1353
|
+
shutil.copy2(script_path, orig_bak)
|
|
1354
|
+
|
|
1355
|
+
|
|
1356
|
+
def _inject_interactive_guard(text: str) -> str:
|
|
1357
|
+
"""Prepend `interactive_guard` after the shebang line if not already present."""
|
|
1358
|
+
if "synth-shell-theme: interactive_guard" in text or "[[ $- != *i* ]] && return" in text:
|
|
1359
|
+
return text
|
|
1360
|
+
lines = text.splitlines()
|
|
1361
|
+
if lines and lines[0].startswith("#!"):
|
|
1362
|
+
lines.insert(1, INTERACTIVE_GUARD_LINE)
|
|
1363
|
+
else:
|
|
1364
|
+
lines.insert(0, INTERACTIVE_GUARD_LINE)
|
|
1365
|
+
return "\n".join(lines) + ("\n" if text.endswith("\n") else "")
|
|
1366
|
+
|
|
1367
|
+
|
|
1368
|
+
def inspect_patches(config_dir: Path | None = None) -> dict[str, bool]:
|
|
1369
|
+
"""Check which runtime enhancements (v1.0 + v1.1 + v1.2) are active in `synth-shell`."""
|
|
1370
|
+
base = config_dir if config_dir is not None else get_config_dir()
|
|
1371
|
+
prompt_sh = get_prompt_script_path(base)
|
|
1372
|
+
greeter_sh = get_greeter_script_path(base)
|
|
1373
|
+
greeter_found = greeter_sh.is_file()
|
|
1374
|
+
|
|
1375
|
+
greeter_amd_temp = False
|
|
1376
|
+
greeter_zfs_arc = False
|
|
1377
|
+
if greeter_found:
|
|
1378
|
+
g_txt = greeter_sh.read_text(encoding="utf-8", errors="replace")
|
|
1379
|
+
greeter_amd_temp = "synth-shell-theme: greeter_amd_temp" in g_txt or not _GREETER_TEMP_RE.search(g_txt)
|
|
1380
|
+
greeter_zfs_arc = "synth-shell-theme: greeter_zfs_arc" in g_txt or not _GREETER_RAM_RE.search(g_txt)
|
|
1381
|
+
|
|
1382
|
+
if not prompt_sh.is_file():
|
|
1383
|
+
return {
|
|
1384
|
+
"prompt_script_found": False,
|
|
1385
|
+
"kube_fast": False,
|
|
1386
|
+
"kube_namespace_prod": False,
|
|
1387
|
+
"git_single_pass": False,
|
|
1388
|
+
"git_wsl_fast": False,
|
|
1389
|
+
"git_ahead_behind_counts": False,
|
|
1390
|
+
"git_advanced_state": False,
|
|
1391
|
+
"dual_separator": False,
|
|
1392
|
+
"color_256_parity": False,
|
|
1393
|
+
"truecolor_24bit": False,
|
|
1394
|
+
"zero_fork_render": False,
|
|
1395
|
+
"v11_segments": False,
|
|
1396
|
+
"v12_segments": False,
|
|
1397
|
+
"v13_segments": False,
|
|
1398
|
+
"osc133_semantic": False,
|
|
1399
|
+
"osc7_cwd": False,
|
|
1400
|
+
"v139_smart_features": False,
|
|
1401
|
+
"terminal_sanitize": False,
|
|
1402
|
+
"right_prompt": False,
|
|
1403
|
+
"responsive_width": False,
|
|
1404
|
+
"hook_chaining": False,
|
|
1405
|
+
"pyenv_enhanced": False,
|
|
1406
|
+
"utf8_ps1_guard": False,
|
|
1407
|
+
"interactive_guard": False,
|
|
1408
|
+
"greeter_script_found": greeter_found,
|
|
1409
|
+
"greeter_amd_temp": greeter_amd_temp,
|
|
1410
|
+
"greeter_zfs_arc": greeter_zfs_arc,
|
|
1411
|
+
"all_applied": False,
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
content = prompt_sh.read_text(encoding="utf-8", errors="replace")
|
|
1415
|
+
m_kube = _GET_KUBE_RE.search(content)
|
|
1416
|
+
kube_body = m_kube.group(0) if m_kube else ""
|
|
1417
|
+
kube_fast = bool(kube_body) and ("yq" not in kube_body) and (
|
|
1418
|
+
"SSP_MAX_KUBE_CHAR" in kube_body or "current-context:" in kube_body
|
|
1419
|
+
)
|
|
1420
|
+
kube_namespace_prod = (
|
|
1421
|
+
("kube_fast v139" in kube_body) if bool(kube_body) else True
|
|
1422
|
+
)
|
|
1423
|
+
git_single_pass = (
|
|
1424
|
+
"synth-shell-theme: git_single_pass" in content
|
|
1425
|
+
or '[[ -n "$(git status --porcelain)" ]]' not in content
|
|
1426
|
+
)
|
|
1427
|
+
git_wsl_fast = (
|
|
1428
|
+
"synth-shell-theme: git_single_pass v13" in content
|
|
1429
|
+
or "synth-shell-theme: git_single_pass v12" in content
|
|
1430
|
+
or "synth-shell-theme: git_single_pass v11" in content
|
|
1431
|
+
or not (_OLD_GIT_RE.search(content) or _V10_GIT_RE.search(content))
|
|
1432
|
+
)
|
|
1433
|
+
git_ahead_behind_counts = (
|
|
1434
|
+
"synth-shell-theme: git_single_pass v13" in content
|
|
1435
|
+
or "synth-shell-theme: git_single_pass v12" in content
|
|
1436
|
+
or not (_OLD_GIT_RE.search(content) or _V10_GIT_RE.search(content) or _V11_GIT_RE.search(content))
|
|
1437
|
+
)
|
|
1438
|
+
git_advanced_state = (
|
|
1439
|
+
"synth-shell-theme: git_single_pass v13" in content
|
|
1440
|
+
or not (_OLD_GIT_RE.search(content) or _V10_GIT_RE.search(content) or _V11_GIT_RE.search(content) or _V12_GIT_RE.search(content))
|
|
1441
|
+
)
|
|
1442
|
+
dual_separator = (
|
|
1443
|
+
'local sep_char="${6:-${separator_char:-}}"' in content
|
|
1444
|
+
or 'local sep_char="${6:-$separator_char}"' in content
|
|
1445
|
+
) and "separator_char_end" in content
|
|
1446
|
+
zero_fork_render = "synth-shell-theme: zero_fork_render" in content
|
|
1447
|
+
utf8_ps1_guard = "synth-shell-theme: utf8_ps1_guard" in content and "${loc,,}" not in content
|
|
1448
|
+
truecolor_24bit = "synth-shell-theme: truecolor_24bit" in content
|
|
1449
|
+
|
|
1450
|
+
has_full_hook = "prompt_command_hook()" in content
|
|
1451
|
+
v11_segments = (
|
|
1452
|
+
("synth-shell-theme: v11_segments" in content and "synth-shell-theme: v11_init" in content)
|
|
1453
|
+
if has_full_hook
|
|
1454
|
+
else True
|
|
1455
|
+
)
|
|
1456
|
+
v12_segments = (
|
|
1457
|
+
("synth-shell-theme: v12_segments" in content and "synth-shell-theme: v12_init" in content)
|
|
1458
|
+
if has_full_hook
|
|
1459
|
+
else True
|
|
1460
|
+
)
|
|
1461
|
+
v13_segments = (
|
|
1462
|
+
("synth-shell-theme: v13_segments" in content and "synth-shell-theme: v13_init" in content)
|
|
1463
|
+
if has_full_hook
|
|
1464
|
+
else True
|
|
1465
|
+
)
|
|
1466
|
+
osc133_semantic = (
|
|
1467
|
+
("synth-shell-theme: osc133_semantic" in content and "133;A\\e\\\\" not in content and "133;C\\e\\\\" not in content)
|
|
1468
|
+
if has_full_hook
|
|
1469
|
+
else True
|
|
1470
|
+
)
|
|
1471
|
+
osc7_cwd = ("synth-shell-theme: osc7_cwd" in content) if has_full_hook else True
|
|
1472
|
+
v139_smart_features = (
|
|
1473
|
+
("synth-shell-theme: v139_smart_features" in content and "synth-shell-theme: v139_init" in content)
|
|
1474
|
+
if has_full_hook
|
|
1475
|
+
else True
|
|
1476
|
+
)
|
|
1477
|
+
terminal_sanitize = ("synth-shell-theme: terminal_sanitize" in content) if has_full_hook else True
|
|
1478
|
+
right_prompt = ("synth-shell-theme: right_prompt" in content) if has_full_hook else True
|
|
1479
|
+
responsive_width = ("synth-shell-theme: responsive_width" in content) if has_full_hook else True
|
|
1480
|
+
hook_chaining = (
|
|
1481
|
+
("synth-shell-theme: hook_chaining" in content and "trap 'echo -ne \"${none}\"' DEBUG" not in content)
|
|
1482
|
+
if has_full_hook
|
|
1483
|
+
else True
|
|
1484
|
+
)
|
|
1485
|
+
has_pyenv_fn = "getPyenv()" in content
|
|
1486
|
+
pyenv_enhanced = ("synth-shell-theme: pyenv_enhanced" in content) if has_pyenv_fn else True
|
|
1487
|
+
|
|
1488
|
+
managed_scripts = [
|
|
1489
|
+
base / name
|
|
1490
|
+
for name in ("synth-shell-prompt.sh", "alias.sh", "better-ls.sh", "better-history.sh")
|
|
1491
|
+
if (base / name).is_file()
|
|
1492
|
+
]
|
|
1493
|
+
if greeter_found and greeter_sh not in managed_scripts:
|
|
1494
|
+
managed_scripts.append(greeter_sh)
|
|
1495
|
+
|
|
1496
|
+
color_files = [
|
|
1497
|
+
base / name
|
|
1498
|
+
for name in ("synth-shell-prompt.sh", "alias.sh", "better-ls.sh", "better-history.sh")
|
|
1499
|
+
if (base / name).is_file()
|
|
1500
|
+
]
|
|
1501
|
+
color_256_parity = bool(color_files) and all(
|
|
1502
|
+
"COLORCODE=$(($BITCODE + 30))" not in f.read_text(encoding="utf-8", errors="replace")
|
|
1503
|
+
for f in color_files
|
|
1504
|
+
)
|
|
1505
|
+
interactive_guard = bool(managed_scripts) and all(
|
|
1506
|
+
(
|
|
1507
|
+
"synth-shell-theme: interactive_guard" in f.read_text(encoding="utf-8", errors="replace")
|
|
1508
|
+
or "[[ $- != *i* ]] && return" in f.read_text(encoding="utf-8", errors="replace")
|
|
1509
|
+
)
|
|
1510
|
+
for f in managed_scripts
|
|
1511
|
+
)
|
|
1512
|
+
|
|
1513
|
+
all_ok = (
|
|
1514
|
+
kube_fast
|
|
1515
|
+
and kube_namespace_prod
|
|
1516
|
+
and git_single_pass
|
|
1517
|
+
and git_wsl_fast
|
|
1518
|
+
and git_ahead_behind_counts
|
|
1519
|
+
and git_advanced_state
|
|
1520
|
+
and dual_separator
|
|
1521
|
+
and color_256_parity
|
|
1522
|
+
and truecolor_24bit
|
|
1523
|
+
and zero_fork_render
|
|
1524
|
+
and v11_segments
|
|
1525
|
+
and v12_segments
|
|
1526
|
+
and v13_segments
|
|
1527
|
+
and osc133_semantic
|
|
1528
|
+
and osc7_cwd
|
|
1529
|
+
and v139_smart_features
|
|
1530
|
+
and terminal_sanitize
|
|
1531
|
+
and right_prompt
|
|
1532
|
+
and responsive_width
|
|
1533
|
+
and hook_chaining
|
|
1534
|
+
and pyenv_enhanced
|
|
1535
|
+
and utf8_ps1_guard
|
|
1536
|
+
and interactive_guard
|
|
1537
|
+
and (not greeter_found or (greeter_amd_temp and greeter_zfs_arc))
|
|
1538
|
+
)
|
|
1539
|
+
|
|
1540
|
+
return {
|
|
1541
|
+
"prompt_script_found": True,
|
|
1542
|
+
"kube_fast": kube_fast,
|
|
1543
|
+
"kube_namespace_prod": kube_namespace_prod,
|
|
1544
|
+
"git_single_pass": git_single_pass,
|
|
1545
|
+
"git_wsl_fast": git_wsl_fast,
|
|
1546
|
+
"git_ahead_behind_counts": git_ahead_behind_counts,
|
|
1547
|
+
"git_advanced_state": git_advanced_state,
|
|
1548
|
+
"dual_separator": dual_separator,
|
|
1549
|
+
"color_256_parity": color_256_parity,
|
|
1550
|
+
"truecolor_24bit": truecolor_24bit,
|
|
1551
|
+
"zero_fork_render": zero_fork_render,
|
|
1552
|
+
"v11_segments": v11_segments,
|
|
1553
|
+
"v12_segments": v12_segments,
|
|
1554
|
+
"v13_segments": v13_segments,
|
|
1555
|
+
"osc133_semantic": osc133_semantic,
|
|
1556
|
+
"osc7_cwd": osc7_cwd,
|
|
1557
|
+
"v139_smart_features": v139_smart_features,
|
|
1558
|
+
"terminal_sanitize": terminal_sanitize,
|
|
1559
|
+
"right_prompt": right_prompt,
|
|
1560
|
+
"responsive_width": responsive_width,
|
|
1561
|
+
"hook_chaining": hook_chaining,
|
|
1562
|
+
"pyenv_enhanced": pyenv_enhanced,
|
|
1563
|
+
"utf8_ps1_guard": utf8_ps1_guard,
|
|
1564
|
+
"interactive_guard": interactive_guard,
|
|
1565
|
+
"greeter_script_found": greeter_found,
|
|
1566
|
+
"greeter_amd_temp": greeter_amd_temp,
|
|
1567
|
+
"greeter_zfs_arc": greeter_zfs_arc,
|
|
1568
|
+
"all_applied": all_ok,
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
|
|
1572
|
+
def apply_runtime_patches(
|
|
1573
|
+
config_dir: Path | None = None,
|
|
1574
|
+
tune_defaults: bool = False,
|
|
1575
|
+
) -> dict[str, object]:
|
|
1576
|
+
"""Idempotently apply all v1.0 + v1.1 + v1.2 runtime, speed, TrueColor, hook-chaining & safety patches."""
|
|
1577
|
+
base = config_dir if config_dir is not None else get_config_dir()
|
|
1578
|
+
prompt_sh = get_prompt_script_path(base)
|
|
1579
|
+
greeter_sh = get_greeter_script_path(base)
|
|
1580
|
+
bdir = get_backup_dir(base)
|
|
1581
|
+
changes: list[str] = []
|
|
1582
|
+
|
|
1583
|
+
if prompt_sh.is_file():
|
|
1584
|
+
original = prompt_sh.read_text(encoding="utf-8", errors="replace")
|
|
1585
|
+
updated = original
|
|
1586
|
+
|
|
1587
|
+
# 1. Fast zero-subshell kube context + namespace + prod warning reader (v139)
|
|
1588
|
+
m_kube = _GET_KUBE_RE.search(updated)
|
|
1589
|
+
if m_kube and ("kube_fast v139" not in m_kube.group(0)):
|
|
1590
|
+
updated = _GET_KUBE_RE.sub(lambda _: FAST_GET_KUBE, updated, count=1)
|
|
1591
|
+
changes.append("kube_fast")
|
|
1592
|
+
changes.append("kube_namespace_prod")
|
|
1593
|
+
|
|
1594
|
+
# 2. Single-pass git status + WSL2 fast-untracked + timeout + async + counts + rebase/merge/worktree
|
|
1595
|
+
if _OLD_GIT_RE.search(updated):
|
|
1596
|
+
updated = _OLD_GIT_RE.sub(lambda _: SINGLE_PASS_GIT_V13, updated, count=1)
|
|
1597
|
+
changes.append("git_single_pass")
|
|
1598
|
+
changes.append("git_ahead_behind_counts")
|
|
1599
|
+
changes.append("git_advanced_state")
|
|
1600
|
+
elif _V10_GIT_RE.search(updated):
|
|
1601
|
+
updated = _V10_GIT_RE.sub(lambda _: SINGLE_PASS_GIT_V13, updated, count=1)
|
|
1602
|
+
changes.append("git_wsl_fast")
|
|
1603
|
+
changes.append("git_ahead_behind_counts")
|
|
1604
|
+
changes.append("git_advanced_state")
|
|
1605
|
+
elif _V11_GIT_RE.search(updated):
|
|
1606
|
+
updated = _V11_GIT_RE.sub(lambda _: SINGLE_PASS_GIT_V13, updated, count=1)
|
|
1607
|
+
changes.append("git_ahead_behind_counts")
|
|
1608
|
+
changes.append("git_advanced_state")
|
|
1609
|
+
elif _V12_GIT_RE.search(updated):
|
|
1610
|
+
updated = _V12_GIT_RE.sub(lambda _: SINGLE_PASS_GIT_V13, updated, count=1)
|
|
1611
|
+
changes.append("git_advanced_state")
|
|
1612
|
+
|
|
1613
|
+
# 3. Zero-fork segment renderer + UTF-8 PS1 escape guard + TrueColor 24-bit (#RRGGBB)
|
|
1614
|
+
if "synth-shell-theme: truecolor_24bit" not in updated or "${loc,,}" in updated:
|
|
1615
|
+
if _ZERO_FORK_BLOCK_RE.search(updated):
|
|
1616
|
+
updated = _ZERO_FORK_BLOCK_RE.sub(lambda _: ZERO_FORK_V12_HELPERS, updated, count=1)
|
|
1617
|
+
if _PRINT_SEG_FULL_RE.search(updated):
|
|
1618
|
+
updated = _PRINT_SEG_FULL_RE.sub(lambda _: PATCHED_PRINT_SEGMENT, updated, count=1)
|
|
1619
|
+
changes.append("truecolor_24bit")
|
|
1620
|
+
elif _PRINT_SEG_FULL_RE.search(updated):
|
|
1621
|
+
updated = _PRINT_SEG_FULL_RE.sub(
|
|
1622
|
+
lambda _: f"{ZERO_FORK_V12_HELPERS}\n{PATCHED_PRINT_SEGMENT}",
|
|
1623
|
+
updated,
|
|
1624
|
+
count=1,
|
|
1625
|
+
)
|
|
1626
|
+
changes.append("zero_fork_render")
|
|
1627
|
+
changes.append("utf8_ps1_guard")
|
|
1628
|
+
changes.append("truecolor_24bit")
|
|
1629
|
+
|
|
1630
|
+
# Ensure `dual_separator` is wired in `combine_elements` even on minimal scripts
|
|
1631
|
+
if "separator_char_end" not in updated:
|
|
1632
|
+
step_comb = _COMBINE_TAIL_RE.sub(
|
|
1633
|
+
(
|
|
1634
|
+
r"\1"
|
|
1635
|
+
'\tlocal sep_char="$separator_char"\n'
|
|
1636
|
+
'\tif [ "$second" = "INPUT" ] && [ -n "${separator_char_end:-}" ]; then\n'
|
|
1637
|
+
'\t\tsep_char="$separator_char_end"\n'
|
|
1638
|
+
"\tfi\n"
|
|
1639
|
+
'\tprintSegment "$text" "$text_color" "$bg_color" "$next_bg_color" "$text_effect" "$sep_char"'
|
|
1640
|
+
r"\2"
|
|
1641
|
+
),
|
|
1642
|
+
updated,
|
|
1643
|
+
count=1,
|
|
1644
|
+
)
|
|
1645
|
+
if step_comb != updated:
|
|
1646
|
+
updated = step_comb
|
|
1647
|
+
changes.append("dual_separator")
|
|
1648
|
+
|
|
1649
|
+
# 4. Enhanced pure-Bash getPyenv (`VIRTUAL_ENV_PROMPT`, `pyvenv.cfg`, Conda, `max_pyenv_char`)
|
|
1650
|
+
m_py = _GET_PYENV_RE.search(updated)
|
|
1651
|
+
if m_py and "synth-shell-theme: pyenv_enhanced" not in m_py.group(0):
|
|
1652
|
+
updated = _GET_PYENV_RE.sub(lambda _: ENHANCED_GET_PYENV, updated, count=1)
|
|
1653
|
+
changes.append("pyenv_enhanced")
|
|
1654
|
+
|
|
1655
|
+
# 5. Italic & regular text effect support in `getEffectCode()`
|
|
1656
|
+
m_eff = _GET_EFFECT_RE.search(updated)
|
|
1657
|
+
if m_eff and "italic)" not in m_eff.group(0):
|
|
1658
|
+
eff_patched = m_eff.group(0).replace(
|
|
1659
|
+
"\tdim)\n\t\techo 2\n\t\t;;",
|
|
1660
|
+
"\tdim)\n\t\techo 2\n\t\t;;\n\titalic)\n\t\techo 3\n\t\t;;\n\tregular)\n\t\techo 0\n\t\t;;",
|
|
1661
|
+
)
|
|
1662
|
+
if eff_patched != m_eff.group(0):
|
|
1663
|
+
updated = updated[: m_eff.start()] + eff_patched + updated[m_eff.end() :]
|
|
1664
|
+
changes.append("font_effects")
|
|
1665
|
+
|
|
1666
|
+
# 6. Phase 2, 3, v1.2 & v1.3 segments + RPROMPT + OSC 133 + safe PROMPT_COMMAND chaining
|
|
1667
|
+
if "prompt_command_hook()" in updated and (
|
|
1668
|
+
"synth-shell-theme: v13_segments" not in updated
|
|
1669
|
+
or "synth-shell-theme: v13_init" not in updated
|
|
1670
|
+
or "synth-shell-theme: v139_smart_features" not in updated
|
|
1671
|
+
or "synth-shell-theme: v139_init" not in updated
|
|
1672
|
+
or "synth-shell-theme: osc133_semantic" not in updated
|
|
1673
|
+
or "synth-shell-theme: osc7_cwd" not in updated
|
|
1674
|
+
or "synth-shell-theme: terminal_sanitize" not in updated
|
|
1675
|
+
or "synth-shell-theme: right_prompt" not in updated
|
|
1676
|
+
or "133;A\\e\\\\" in updated
|
|
1677
|
+
or "133;C\\e\\\\" in updated
|
|
1678
|
+
or "${os_id,,}" in updated
|
|
1679
|
+
or "_ssp_had_u" not in updated
|
|
1680
|
+
):
|
|
1681
|
+
had_dual = "separator_char_end" in updated
|
|
1682
|
+
if _V11_SEGS_BLOCK_RE.search(updated):
|
|
1683
|
+
updated = _V11_SEGS_BLOCK_RE.sub(
|
|
1684
|
+
lambda _: f"{V12_SEGMENTS_BLOCK}\n{V12_COLORS_FOR_ELEMENT}",
|
|
1685
|
+
updated,
|
|
1686
|
+
count=1,
|
|
1687
|
+
)
|
|
1688
|
+
elif _GET_COLORS_RE.search(updated):
|
|
1689
|
+
updated = _GET_COLORS_RE.sub(
|
|
1690
|
+
lambda _: f"{V12_SEGMENTS_BLOCK}\n{V12_COLORS_FOR_ELEMENT}",
|
|
1691
|
+
updated,
|
|
1692
|
+
count=1,
|
|
1693
|
+
)
|
|
1694
|
+
|
|
1695
|
+
if _COMBINE_V11_RE.search(updated):
|
|
1696
|
+
updated = _COMBINE_V11_RE.sub(lambda _: V12_COMBINE_ELEMENTS, updated, count=1)
|
|
1697
|
+
elif _COMBINE_FULL_RE.search(updated):
|
|
1698
|
+
updated = _COMBINE_FULL_RE.sub(lambda _: V12_COMBINE_ELEMENTS, updated, count=1)
|
|
1699
|
+
|
|
1700
|
+
if _PROMPT_HOOK_RE.search(updated):
|
|
1701
|
+
updated = _PROMPT_HOOK_RE.sub(lambda _: V12_PROMPT_COMMAND_HOOK, updated, count=1)
|
|
1702
|
+
|
|
1703
|
+
# Remove destructive DEBUG trap (replaced by PS0 reset)
|
|
1704
|
+
updated = _DEBUG_TRAP_RE.sub("", updated, count=1)
|
|
1705
|
+
|
|
1706
|
+
if "synth-shell-theme: v139_init" not in updated or "133;C\\e\\\\" in updated or "SSP_TERMINAL_SANITIZE" not in updated:
|
|
1707
|
+
if _V11_INIT_AND_PC_RE.search(updated):
|
|
1708
|
+
updated = _V11_INIT_AND_PC_RE.sub(lambda _: V12_INIT_AND_CHAINING, updated, count=1)
|
|
1709
|
+
elif "\tPROMPT_COMMAND=prompt_command_hook" in updated:
|
|
1710
|
+
updated = updated.replace("\tPROMPT_COMMAND=prompt_command_hook", V12_INIT_AND_CHAINING, 1)
|
|
1711
|
+
|
|
1712
|
+
changes.append("v13_segments")
|
|
1713
|
+
changes.append("v139_smart_features")
|
|
1714
|
+
changes.append("osc133_semantic")
|
|
1715
|
+
changes.append("osc7_cwd")
|
|
1716
|
+
changes.append("terminal_sanitize")
|
|
1717
|
+
changes.append("right_prompt")
|
|
1718
|
+
if "hook_chaining" not in changes:
|
|
1719
|
+
changes.append("hook_chaining")
|
|
1720
|
+
if not had_dual and "dual_separator" not in changes:
|
|
1721
|
+
changes.append("dual_separator")
|
|
1722
|
+
|
|
1723
|
+
if updated != original:
|
|
1724
|
+
_backup_script_once(prompt_sh, bdir)
|
|
1725
|
+
prompt_sh.write_text(updated, encoding="utf-8", newline="\n")
|
|
1726
|
+
|
|
1727
|
+
# 7. 256-color + TrueColor parity & non-interactive shell guard across all synth-shell scripts
|
|
1728
|
+
script_names = ["synth-shell-prompt.sh", "alias.sh", "better-ls.sh", "better-history.sh"]
|
|
1729
|
+
if greeter_sh.is_file() and greeter_sh.name not in script_names:
|
|
1730
|
+
script_names.append(greeter_sh.name)
|
|
1731
|
+
|
|
1732
|
+
for script_name in script_names:
|
|
1733
|
+
script_file = base / script_name
|
|
1734
|
+
if not script_file.is_file():
|
|
1735
|
+
continue
|
|
1736
|
+
txt = script_file.read_text(encoding="utf-8", errors="replace")
|
|
1737
|
+
new_txt = txt
|
|
1738
|
+
needs_color_upgrade = (
|
|
1739
|
+
"COLORCODE=$(($BITCODE + 30))" in new_txt
|
|
1740
|
+
or ("synth-shell-theme: color_256_parity" in new_txt and "truecolor_24bit" not in new_txt)
|
|
1741
|
+
)
|
|
1742
|
+
if needs_color_upgrade and _COLOR_BLOCK_RE.search(new_txt):
|
|
1743
|
+
replaced = _COLOR_BLOCK_RE.sub(lambda _: PATCHED_COLOR_CODES, new_txt, count=1)
|
|
1744
|
+
if replaced != new_txt:
|
|
1745
|
+
new_txt = replaced
|
|
1746
|
+
changes.append(f"color_256_parity:{script_name}")
|
|
1747
|
+
|
|
1748
|
+
guarded = _inject_interactive_guard(new_txt)
|
|
1749
|
+
if guarded != new_txt:
|
|
1750
|
+
new_txt = guarded
|
|
1751
|
+
changes.append(f"interactive_guard:{script_name}")
|
|
1752
|
+
|
|
1753
|
+
if new_txt != txt:
|
|
1754
|
+
_backup_script_once(script_file, bdir)
|
|
1755
|
+
script_file.write_text(new_txt, encoding="utf-8", newline="\n")
|
|
1756
|
+
|
|
1757
|
+
# 8. Optional Greeter runtime fixes (AMD k10temp/Tctl CPU temp + ZFS ARC memory accounting)
|
|
1758
|
+
if greeter_sh.is_file():
|
|
1759
|
+
g_orig = greeter_sh.read_text(encoding="utf-8", errors="replace")
|
|
1760
|
+
g_new = g_orig
|
|
1761
|
+
m_gt = _GREETER_TEMP_RE.search(g_new)
|
|
1762
|
+
if m_gt and "synth-shell-theme: greeter_amd_temp" not in m_gt.group(0):
|
|
1763
|
+
g_new = _GREETER_TEMP_RE.sub(lambda _: PATCHED_GREETER_AMD_TEMP, g_new, count=1)
|
|
1764
|
+
changes.append("greeter_amd_temp")
|
|
1765
|
+
m_gr = _GREETER_RAM_RE.search(g_new)
|
|
1766
|
+
if m_gr and "synth-shell-theme: greeter_zfs_arc" not in m_gr.group(0):
|
|
1767
|
+
g_new = _GREETER_RAM_RE.sub(lambda _: PATCHED_GREETER_ZFS_RAM, g_new, count=1)
|
|
1768
|
+
changes.append("greeter_zfs_arc")
|
|
1769
|
+
if g_new != g_orig:
|
|
1770
|
+
_backup_script_once(greeter_sh, bdir)
|
|
1771
|
+
greeter_sh.write_text(g_new, encoding="utf-8", newline="\n")
|
|
1772
|
+
|
|
1773
|
+
# Optional sensible prompt config defaults (`init` without `--no-tune`)
|
|
1774
|
+
cfg_path = get_config_path(base)
|
|
1775
|
+
if tune_defaults and cfg_path.is_file():
|
|
1776
|
+
cfg_lines = cfg_path.read_text(encoding="utf-8", errors="replace").splitlines()
|
|
1777
|
+
out_lines: list[str] = []
|
|
1778
|
+
has_end_sep = False
|
|
1779
|
+
cfg_changed = False
|
|
1780
|
+
for line in cfg_lines:
|
|
1781
|
+
if line.startswith("max_pwd_char="):
|
|
1782
|
+
if line != 'max_pwd_char="35"':
|
|
1783
|
+
cfg_changed = True
|
|
1784
|
+
out_lines.append('max_pwd_char="35"')
|
|
1785
|
+
elif line.startswith("enable_command_on_new_line="):
|
|
1786
|
+
if line != 'enable_command_on_new_line="true"':
|
|
1787
|
+
cfg_changed = True
|
|
1788
|
+
out_lines.append('enable_command_on_new_line="true"')
|
|
1789
|
+
elif line.startswith("separator_char="):
|
|
1790
|
+
out_lines.append('separator_char="\\uE0B4"')
|
|
1791
|
+
elif line.startswith("separator_char_end="):
|
|
1792
|
+
has_end_sep = True
|
|
1793
|
+
out_lines.append(line)
|
|
1794
|
+
else:
|
|
1795
|
+
out_lines.append(line)
|
|
1796
|
+
if not has_end_sep:
|
|
1797
|
+
out_lines.append('separator_char_end="\\uE0B0"')
|
|
1798
|
+
cfg_changed = True
|
|
1799
|
+
if cfg_changed:
|
|
1800
|
+
stamp = datetime.now().strftime("%Y%m%d-%H%M%S")
|
|
1801
|
+
bdir.mkdir(parents=True, exist_ok=True)
|
|
1802
|
+
shutil.copy2(cfg_path, bdir / f"synth-shell-prompt.config.{stamp}.bak")
|
|
1803
|
+
cfg_path.write_text("\n".join(out_lines) + "\n", encoding="utf-8", newline="\n")
|
|
1804
|
+
changes.append("tune_defaults")
|
|
1805
|
+
|
|
1806
|
+
status = inspect_patches(base)
|
|
1807
|
+
return {
|
|
1808
|
+
"changes": changes,
|
|
1809
|
+
"status": status,
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
|
|
1813
|
+
def ensure_dual_separator_support(config_dir: Path | None = None) -> bool:
|
|
1814
|
+
"""Ensure `synth-shell-prompt.sh` supports `separator_char_end` before writing dual separators."""
|
|
1815
|
+
status = inspect_patches(config_dir)
|
|
1816
|
+
if not status["prompt_script_found"]:
|
|
1817
|
+
return False
|
|
1818
|
+
if status["dual_separator"]:
|
|
1819
|
+
return True
|
|
1820
|
+
res = apply_runtime_patches(config_dir=config_dir, tune_defaults=False)
|
|
1821
|
+
new_status = res["status"]
|
|
1822
|
+
return bool(isinstance(new_status, dict) and new_status.get("dual_separator"))
|
|
1823
|
+
|
|
1824
|
+
|
|
1825
|
+
def install_upstream_synth_shell() -> bool:
|
|
1826
|
+
"""Clone and run upstream `andresgongora/synth-shell` user installer non-interactively."""
|
|
1827
|
+
if shutil.which("git") is None or shutil.which("bash") is None:
|
|
1828
|
+
return False
|
|
1829
|
+
with tempfile.TemporaryDirectory(prefix="synth-shell-install-") as tmp:
|
|
1830
|
+
clone_cmd = [
|
|
1831
|
+
"git",
|
|
1832
|
+
"clone",
|
|
1833
|
+
"--recursive",
|
|
1834
|
+
"--depth=1",
|
|
1835
|
+
"https://github.com/andresgongora/synth-shell.git",
|
|
1836
|
+
tmp,
|
|
1837
|
+
]
|
|
1838
|
+
res_clone = subprocess.run(clone_cmd, capture_output=True, text=True, check=False)
|
|
1839
|
+
if res_clone.returncode != 0:
|
|
1840
|
+
return False
|
|
1841
|
+
setup_sh = Path(tmp) / "setup.sh"
|
|
1842
|
+
if not setup_sh.is_file():
|
|
1843
|
+
return False
|
|
1844
|
+
setup_sh.chmod(0o755)
|
|
1845
|
+
# Answers: i=install, u=user, n=skip greeter, y=prompt, y=better-ls, y=alias, y=better-history
|
|
1846
|
+
res_setup = subprocess.run(
|
|
1847
|
+
["bash", str(setup_sh)],
|
|
1848
|
+
input="iunyyyy",
|
|
1849
|
+
capture_output=True,
|
|
1850
|
+
text=True,
|
|
1851
|
+
check=False,
|
|
1852
|
+
)
|
|
1853
|
+
return res_setup.returncode == 0
|