Skip to content

Commit 0cc6c45

Browse files
authored
detect if omz is installed and shell completion mode in zsh (#2891)
1 parent fb060de commit 0cc6c45

4 files changed

Lines changed: 37 additions & 3 deletions

File tree

frontend/app/view/term/osc-handlers.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type ShellIntegrationStatus = "ready" | "running-command";
2929
type Osc16162Command =
3030
| { command: "A"; data: {} }
3131
| { command: "C"; data: { cmd64?: string } }
32-
| { command: "M"; data: { shell?: string; shellversion?: string; uname?: string; integration?: boolean } }
32+
| { command: "M"; data: { shell?: string; shellversion?: string; uname?: string; integration?: boolean; omz?: boolean; comp?: string } }
3333
| { command: "D"; data: { exitcode?: number } }
3434
| { command: "I"; data: { inputempty?: boolean } }
3535
| { command: "R"; data: {} };
@@ -302,6 +302,12 @@ export function handleOsc16162Command(data: string, blockId: string, loaded: boo
302302
if (cmd.data.integration != null) {
303303
rtInfo["shell:integration"] = cmd.data.integration;
304304
}
305+
if (cmd.data.omz != null) {
306+
rtInfo["shell:omz"] = cmd.data.omz;
307+
}
308+
if (cmd.data.comp != null) {
309+
rtInfo["shell:comp"] = cmd.data.comp;
310+
}
305311
break;
306312
case "D":
307313
if (cmd.data.exitcode != null) {

frontend/types/gotypes.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,8 @@ declare global {
11471147
"shell:version"?: string;
11481148
"shell:uname"?: string;
11491149
"shell:integration"?: boolean;
1150+
"shell:omz"?: boolean;
1151+
"shell:comp"?: string;
11501152
"shell:inputempty"?: boolean;
11511153
"shell:lastcmd"?: string;
11521154
"shell:lastcmdexitcode"?: number;

pkg/util/shellutil/shellintegration/zsh_zshrc.sh

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ _waveterm_si_urlencode() {
4848
fi
4949
}
5050

51+
_waveterm_si_compmode() {
52+
# fzf-based completion wins
53+
if typeset -f _fzf_tab_complete >/dev/null 2>&1 || typeset -f _fzf_complete >/dev/null 2>&1; then
54+
echo "fzf"
55+
return
56+
fi
57+
58+
# Check zstyle menu setting
59+
local _menuval
60+
if zstyle -s ':completion:*' menu _menuval 2>/dev/null; then
61+
if [[ "$_menuval" == *select* ]]; then
62+
echo "menu-select"
63+
else
64+
echo "menu"
65+
fi
66+
return
67+
fi
68+
69+
echo "standard"
70+
}
71+
5172
_waveterm_si_osc7() {
5273
_waveterm_si_blocked && return
5374
local encoded_pwd=$(_waveterm_si_urlencode "$PWD")
@@ -59,10 +80,13 @@ _waveterm_si_precmd() {
5980
_waveterm_si_blocked && return
6081
# D;status for previous command (skip before first prompt)
6182
if (( !_WAVETERM_SI_FIRSTPRECMD )); then
62-
printf '\033]16162;D;{"exitcode":%d}\007' $_waveterm_si_status
83+
printf '\033]16162;D;{"exitcode":%d}\007' "$_waveterm_si_status"
6384
else
6485
local uname_info=$(uname -smr 2>/dev/null)
65-
printf '\033]16162;M;{"shell":"zsh","shellversion":"%s","uname":"%s","integration":true}\007' "$ZSH_VERSION" "$uname_info"
86+
local omz=false
87+
local comp=$(_waveterm_si_compmode)
88+
[[ -n "$ZSH" && -r "$ZSH/oh-my-zsh.sh" ]] && omz=true
89+
printf '\033]16162;M;{"shell":"zsh","shellversion":"%s","uname":"%s","integration":true,"omz":%s,"comp":"%s"}\007' "$ZSH_VERSION" "$uname_info" "$omz" "$comp"
6690
# OSC 7 only sent on first prompt - chpwd hook handles directory changes
6791
_waveterm_si_osc7
6892
fi

pkg/waveobj/objrtinfo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type ObjRTInfo struct {
1313
ShellVersion string `json:"shell:version,omitempty"`
1414
ShellUname string `json:"shell:uname,omitempty"`
1515
ShellIntegration bool `json:"shell:integration,omitempty"`
16+
ShellOmz bool `json:"shell:omz,omitempty"`
17+
ShellComp string `json:"shell:comp,omitempty"`
1618
ShellInputEmpty bool `json:"shell:inputempty,omitempty"`
1719
ShellLastCmd string `json:"shell:lastcmd,omitempty"`
1820
ShellLastCmdExitCode int `json:"shell:lastcmdexitcode,omitempty"`

0 commit comments

Comments
 (0)