1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/zsh
# par-term Shell Integration for Zsh
#
# This script provides shell integration markers for par-term terminal.
# Based on OSC 133 standard (also used by iTerm2, VSCode, etc.)
#
# Features:
# - Prompt navigation (jump between commands)
# - Command status tracking (exit codes)
# - Working directory tracking
# - Command duration measurement
# - Smart selection (select command vs output)
#
# Usage:
# Add to your ~/.zshrc:
# source "${XDG_CONFIG_HOME:-$HOME/.config}/par-term/shell_integration.zsh"
if ; then
if [; then
PAR_TERM_SHELL_INTEGRATION_INSTALLED=Yes
PAR_TERM_SHOULD_DECORATE_PROMPT="1"
# OSC 133 ; C - Mark command execution start
# Optional $1: command text (passed by preexec hook)
# Set a user-defined variable
# Usage: par_term_set_user_var key value
# Example: par_term_set_user_var git_branch "$(git branch --show-current 2>/dev/null)"
# Users can write their own version of this function
# It should call par_term_set_user_var but not produce any other output
if [; then
fi
# Send current directory and custom user vars
# OSC 133 ; D ; exit_code - Report command exit status
# OSC 133 ; A - Mark prompt start
# OSC 133 ; B - Mark prompt end (command input starts)
# Zsh prompt lifecycle:
#
# 1) A command is entered at the prompt and you press return:
# * par_term_preexec is invoked
# * PS1 is set to PAR_TERM_PRECMD_PS1
# * PAR_TERM_SHOULD_DECORATE_PROMPT is set to 1
# * The command executes (possibly reading or modifying PS1)
# * par_term_precmd is invoked
# * PAR_TERM_PRECMD_PS1 is set to PS1 (as modified by command)
# * PS1 gets our escape sequences added to it
# * zsh displays your prompt
#
# 2) You press ^C while entering a command:
# * (par_term_preexec is NOT invoked)
# * par_term_precmd is invoked
# * par_term_before_cmd_executes is called
# * PS1 already has escape sequences
#
# 3) A new shell is born:
# * PS1 has initial value
# * par_term_precmd is invoked
# * PAR_TERM_SHOULD_DECORATE_PROMPT is set to 1
# * PAR_TERM_PRECMD_PS1 is set to initial PS1
# * PS1 gets our escape sequences added to it
# Called before each prompt display
# Called before each command execution (not run if you press ^C)
# $1: the full command line (provided by zsh's preexec hook)
# Cache hostname if not on macOS (where it can change with VPN)
if [; then
if [; then
par_term_hostname=
# Some BSDs don't have -f option
if [; then
par_term_hostname=
fi
fi
fi
# Register our functions with zsh's hook arrays
&& precmd_functions=()
precmd_functions=( par_term_precmd)
&& preexec_functions=()
preexec_functions=( par_term_preexec)
# Send initial state
# Identify shell integration version
fi
fi