@@ -98,6 +98,32 @@ function __vsc_cmd_clear --on-event fish_cancel
98
98
__vsc_esc D
99
99
end
100
100
101
+ # Preserve the user' s existing prompt, to wrap in our escape sequences.
102
+ function __preserve_fish_prompt --on-event fish_prompt
103
+ if functions --query fish_prompt
104
+ if functions --query __vsc_fish_prompt
105
+ # Erase the fallback so it can be set to the user's prompt
106
+ functions --erase __vsc_fish_prompt
107
+ end
108
+ functions --copy fish_prompt __vsc_fish_prompt
109
+ functions --erase __preserve_fish_prompt
110
+ # Now __vsc_fish_prompt is guaranteed to be defined
111
+ __init_vscode_shell_integration
112
+ else
113
+ if functions --query __vsc_fish_prompt
114
+ functions --erase __preserve_fish_prompt
115
+ __init_vscode_shell_integration
116
+ else
117
+ # There is no fish_prompt set, so stick with the default
118
+ # Now __vsc_fish_prompt is guaranteed to be defined
119
+ function __vsc_fish_prompt
120
+ echo -n (whoami)@(prompt_hostname) (prompt_pwd ) ' ~> '
121
+ end
122
+ end
123
+ end
124
+ end
125
+ __preserve_fish_prompt
126
+
101
127
# Sent whenever a new fish prompt is about to be displayed.
102
128
# Updates the current working directory.
103
129
function __vsc_update_cwd --on-event fish_prompt
@@ -128,29 +154,28 @@ function __vsc_fish_has_mode_prompt -d "Returns true if fish_mode_prompt is defi
128
154
functions fish_mode_prompt | string match -rvq ' ^ *(#|function |end$|$)'
129
155
end
130
156
131
- # Preserve the user's existing prompt, to wrap in our escape sequences.
132
- functions --copy fish_prompt __vsc_fish_prompt
133
-
134
157
# Preserve and wrap fish_mode_prompt (which appears to the left of the regular
135
158
# prompt), but only if it's not defined as an empty function (which is the
136
159
# officially documented way to disable that feature).
137
- if __vsc_fish_has_mode_prompt
138
- functions --copy fish_mode_prompt __vsc_fish_mode_prompt
139
-
140
- function fish_mode_prompt
141
- __vsc_fish_prompt_start
142
- __vsc_fish_mode_prompt
143
- end
144
-
145
- function fish_prompt
146
- __vsc_fish_prompt
147
- __vsc_fish_cmd_start
148
- end
149
- else
150
- # No fish_mode_prompt, so put everything in fish_prompt.
151
- function fish_prompt
152
- __vsc_fish_prompt_start
153
- __vsc_fish_prompt
154
- __vsc_fish_cmd_start
160
+ function __init_vscode_shell_integration
161
+ if __vsc_fish_has_mode_prompt
162
+ functions --copy fish_mode_prompt __vsc_fish_mode_prompt
163
+
164
+ function fish_mode_prompt
165
+ __vsc_fish_prompt_start
166
+ __vsc_fish_mode_prompt
167
+ end
168
+
169
+ function fish_prompt
170
+ __vsc_fish_prompt
171
+ __vsc_fish_cmd_start
172
+ end
173
+ else
174
+ # No fish_mode_prompt, so put everything in fish_prompt.
175
+ function fish_prompt
176
+ __vsc_fish_prompt_start
177
+ __vsc_fish_prompt
178
+ __vsc_fish_cmd_start
179
+ end
155
180
end
156
181
end
0 commit comments