@@ -4,14 +4,20 @@ set --export --global POWERLINE_COMMAND oh-my-posh
44set --export --global CONDA_PROMPT_MODIFIER false
55
66set --global _omp_tooltip_command ' '
7+ set --global _omp_current_rprompt ' '
8+ set --global _omp_transient 0
79set --global _omp_executable ::OMP::
810set --global _omp_ftcs_marks 0
11+ set --global _omp_transient_prompt 0
912set --global _omp_prompt_mark 0
1013
1114# disable all known python virtual environment prompts
1215set --global VIRTUAL_ENV_DISABLE_PROMPT 1
1316set --global PYENV_VIRTUALENV_DISABLE_PROMPT 1
1417
18+ # We use this to avoid unnecessary CLI calls for prompt repaint.
19+ set --global _omp_new_prompt 1
20+
1521# template function for context loading
1622function set_poshcontext
1723 return
3844function fish_prompt
3945 set --local omp_status_temp $status
4046 set --local omp_pipestatus_temp $pipestatus
41-
4247 # clear from cursor to end of screen as
4348 # commandline --function repaint does not do this
4449 # see https://github.com/fish-shell/fish-shell/issues/8418
45- # printf \e\[0J
46-
47- if contains -- --final-rendering $argv
48- echo -n (_omp_get_prompt transient)
50+ printf \e\ [0J
51+ if test " $_ omp_transient" = 1
52+ _omp_get_prompt transient
53+ return
54+ end
55+ if test " $_ omp_new_prompt" = 0
56+ echo -n " $_ omp_current_prompt"
4957 return
5058 end
51-
5259 set --global _omp_status $omp_status_temp
5360 set --global _omp_pipestatus $omp_pipestatus_temp
5461 set --global _omp_no_status false
@@ -88,11 +95,28 @@ function fish_prompt
8895 iterm2_prompt_mark
8996 end
9097
91- echo -n (_omp_get_prompt primary --cleared =$omp_cleared | string join \n | string collect)
98+ # The prompt is saved for possible reuse, typically a repaint after clearing the screen buffer.
99+ set --global _omp_current_prompt (_omp_get_prompt primary --cleared =$omp_cleared | string join \n | string collect)
100+
101+ echo -n " $_ omp_current_prompt"
92102end
93103
94104function fish_right_prompt
95- echo -n (_omp_get_prompt right | string join ' ' )
105+ if test " $_ omp_transient" = 1
106+ set --global _omp_transient 0
107+ return
108+ end
109+
110+ # Repaint an existing right prompt.
111+ if test " $_ omp_new_prompt" = 0
112+ echo -n " $_ omp_current_rprompt"
113+ return
114+ end
115+
116+ set --global _omp_new_prompt 0
117+ set --global _omp_current_rprompt (_omp_get_prompt right | string join ' ' )
118+
119+ echo -n " $_ omp_current_rprompt"
96120end
97121
98122function _omp_postexec --on-event fish_postexec
@@ -107,6 +131,30 @@ function _omp_preexec --on-event fish_preexec
107131 end
108132end
109133
134+ # perform cleanup so a new initialization in current session works
135+ if bind \r --user 2> /dev/null | string match -qe _omp_enter_key_handler
136+ bind -e \r -M default
137+ bind -e \r -M insert
138+ bind -e \r -M visual
139+ end
140+
141+ if bind \n --user 2> /dev/null | string match -qe _omp_enter_key_handler
142+ bind -e \n -M default
143+ bind -e \n -M insert
144+ bind -e \n -M visual
145+ end
146+
147+ if bind \ cc --user 2> /dev/null | string match -qe _omp_ctrl_c_key_handler
148+ bind -e \ cc -M default
149+ bind -e \ cc -M insert
150+ bind -e \ cc -M visual
151+ end
152+
153+ if bind \ x20 --user 2> /dev/null | string match -qe _omp_space_key_handler
154+ bind -e \ x20 -M default
155+ bind -e \ x20 -M insert
156+ end
157+
110158# tooltip
111159
112160function _omp_space_key_handler
@@ -137,3 +185,63 @@ function enable_poshtooltips
137185 bind \ x20 _omp_space_key_handler -M default
138186 bind \ x20 _omp_space_key_handler -M insert
139187end
188+
189+ # transient prompt
190+
191+ function _omp_enter_key_handler
192+ if commandline --paging-mode
193+ commandline --function execute
194+ return
195+ end
196+
197+ if commandline --is-valid || test -z (commandline --current-buffer | string trim -l | string collect)
198+ set --global _omp_new_prompt 1
199+ set --global _omp_tooltip_command ' '
200+
201+ if test $_ omp_transient_prompt = 1
202+ set --global _omp_transient 1
203+ commandline --function repaint
204+ end
205+ end
206+
207+ commandline --function execute
208+ end
209+
210+ function _omp_ctrl_c_key_handler
211+ if test -z (commandline --current-buffer | string collect)
212+ return
213+ end
214+
215+ # Render a transient prompt on Ctrl-C with non-empty command line buffer.
216+ set --global _omp_new_prompt 1
217+ set --global _omp_tooltip_command ' '
218+
219+ if test $_ omp_transient_prompt = 1
220+ set --global _omp_transient 1
221+ commandline --function repaint
222+ end
223+
224+ commandline --function cancel-commandline
225+ commandline --function repaint
226+ end
227+
228+ bind \r _omp_enter_key_handler -M default
229+ bind \r _omp_enter_key_handler -M insert
230+ bind \r _omp_enter_key_handler -M visual
231+ bind \n _omp_enter_key_handler -M default
232+ bind \n _omp_enter_key_handler -M insert
233+ bind \n _omp_enter_key_handler -M visual
234+ bind \ cc _omp_ctrl_c_key_handler -M default
235+ bind \ cc _omp_ctrl_c_key_handler -M insert
236+ bind \ cc _omp_ctrl_c_key_handler -M visual
237+
238+ # legacy functions
239+ function enable_poshtransientprompt
240+ return
241+ end
242+
243+ # This can be called by user whenever re-rendering is required.
244+ function omp_repaint_prompt
245+ set --global _omp_new_prompt 1
246+ commandline --function repaint
247+ end
0 commit comments