@@ -5,7 +5,7 @@ let s:loaded_run = 1
55
66" script vars
77let s: run_jobs = get (s: , ' run_jobs' , {})
8- let s: run_last_command = get (s: , ' run_last_command ' , ' ' )
8+ let s: run_last_commands = get (s: , ' run_last_commands ' , [] )
99let s: run_last_options = get (s: , ' run_last_options' , {})
1010let s: run_killall_ongoing = get (s: , ' run_killall_ongoing' , 0 )
1111let s: run_timestamp_format = get (s: , ' run_timestamp_format' , ' %Y-%m-%d %H:%M:%S' )
@@ -83,7 +83,8 @@ function! run#Run(cmd, ...) abort
8383
8484 if empty (trim (a: cmd ))
8585 " no text provided in cmd input
86- if get (options , ' is_from_editor' ) && ! get (options , ' edit_last' )
86+ let edit_cmd = get (options , ' edit_cmd' , ' ' )
87+ if get (options , ' is_from_editor' ) && empty (edit_cmd)
8788 call run#print_formatted (' WarningMsg' , ' User cancelled command input.' )
8889 return
8990 endif
@@ -98,8 +99,8 @@ function! run#Run(cmd, ...) abort
9899 let s: run_edit_options = options
99100 let s: run_edit_path = s: run_cmd_path . ' edit-' . timestamp . ' .sh'
100101 let editor_lines = [s: edit_msg , ' ' ]
101- if get ( options , ' edit_last ' )
102- call extend (editor_lines, split (s: run_last_command , " \n " ))
102+ if ! empty (edit_cmd )
103+ call extend (editor_lines, split (edit_cmd , " \n " ))
103104 else
104105 call add (editor_lines, ' ' )
105106 endif
@@ -108,7 +109,7 @@ function! run#Run(cmd, ...) abort
108109 return
109110 endif
110111
111- let s: run_last_command = a: cmd
112+ let s: run_last_commands = extend ([ a: cmd], s: run_last_commands )
112113 let s: run_last_options = options
113114 let shortcmd = run#clean_cmd_name (a: cmd )
114115 let fname = timestamp . ' __' . shortcmd . ' .log'
@@ -219,23 +220,47 @@ function! run#RunNoStream(cmd) abort
219220 call run#Run (a: cmd , { ' nostream' : 1 })
220221endfunction
221222
222- function ! run#RunAgain () abort
223- if empty (s: run_last_command )
223+ function ! run#RunAgain (... ) abort
224+ if empty (s: run_last_commands )
224225 call run#print_formatted (' ErrorMsg' , ' Please run a command first.' )
225226 return
226227 endif
227- call run#Run (s: run_last_command , s: run_last_options )
228+ let index = get (a: , 1 )
229+ if empty (index ) | let index = ' 0' | endif
230+ if index !~# ' ^\d\+$'
231+ call run#print_formatted (' ErrorMsg' , ' Index must be a number.' )
232+ return
233+ endif
234+ try
235+ let selected_command = s: run_last_commands [index ]
236+ catch
237+ call run#print_formatted (' ErrorMsg' , ' Index ' .index .' out of range' )
238+ return
239+ endtry
240+ call run#Run (selected_command, s: run_last_options )
228241endfunction
229242
230- function ! run#RunAgainEdit () abort
231- if empty (s: run_last_command )
243+ function ! run#RunAgainEdit (... ) abort
244+ if empty (s: run_last_commands )
232245 call run#print_formatted (' ErrorMsg' , ' Please run a command first.' )
233246 return
234247 endif
248+ let index = get (a: , 1 )
249+ if empty (index ) | let index = ' 0' | endif
250+ if index !~# ' ^\d\+$'
251+ call run#print_formatted (' ErrorMsg' , ' Index must be a number.' )
252+ return
253+ endif
254+ try
255+ let selected_command = s: run_last_commands [index ]
256+ catch
257+ call run#print_formatted (' ErrorMsg' , ' Index ' .index .' out of range' )
258+ return
259+ endtry
235260 let new_opts = deepcopy (s: run_last_options )
236- let new_opts[' edit_last ' ] = 1
261+ let new_opts[' edit_cmd ' ] = selected_command
237262 call run#Run (' ' , new_opts)
238- unlet new_opts[' edit_last ' ]
263+ unlet new_opts[' edit_cmd ' ]
239264 let s: run_last_options = new_opts
240265endfunction
241266
0 commit comments