@@ -5,7 +5,7 @@ let s:loaded_run = 1
5
5
6
6
" script vars
7
7
let 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 ' , [] )
9
9
let s: run_last_options = get (s: , ' run_last_options' , {})
10
10
let s: run_killall_ongoing = get (s: , ' run_killall_ongoing' , 0 )
11
11
let s: run_timestamp_format = get (s: , ' run_timestamp_format' , ' %Y-%m-%d %H:%M:%S' )
@@ -83,7 +83,8 @@ function! run#Run(cmd, ...) abort
83
83
84
84
if empty (trim (a: cmd ))
85
85
" 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)
87
88
call run#print_formatted (' WarningMsg' , ' User cancelled command input.' )
88
89
return
89
90
endif
@@ -98,8 +99,8 @@ function! run#Run(cmd, ...) abort
98
99
let s: run_edit_options = options
99
100
let s: run_edit_path = s: run_cmd_path . ' edit-' . timestamp . ' .sh'
100
101
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 " ))
103
104
else
104
105
call add (editor_lines, ' ' )
105
106
endif
@@ -108,7 +109,7 @@ function! run#Run(cmd, ...) abort
108
109
return
109
110
endif
110
111
111
- let s: run_last_command = a: cmd
112
+ let s: run_last_commands = extend ([ a: cmd], s: run_last_commands )
112
113
let s: run_last_options = options
113
114
let shortcmd = run#clean_cmd_name (a: cmd )
114
115
let fname = timestamp . ' __' . shortcmd . ' .log'
@@ -219,23 +220,47 @@ function! run#RunNoStream(cmd) abort
219
220
call run#Run (a: cmd , { ' nostream' : 1 })
220
221
endfunction
221
222
222
- function ! run#RunAgain () abort
223
- if empty (s: run_last_command )
223
+ function ! run#RunAgain (... ) abort
224
+ if empty (s: run_last_commands )
224
225
call run#print_formatted (' ErrorMsg' , ' Please run a command first.' )
225
226
return
226
227
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 )
228
241
endfunction
229
242
230
- function ! run#RunAgainEdit () abort
231
- if empty (s: run_last_command )
243
+ function ! run#RunAgainEdit (... ) abort
244
+ if empty (s: run_last_commands )
232
245
call run#print_formatted (' ErrorMsg' , ' Please run a command first.' )
233
246
return
234
247
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
235
260
let new_opts = deepcopy (s: run_last_options )
236
- let new_opts[' edit_last ' ] = 1
261
+ let new_opts[' edit_cmd ' ] = selected_command
237
262
call run#Run (' ' , new_opts)
238
- unlet new_opts[' edit_last ' ]
263
+ unlet new_opts[' edit_cmd ' ]
239
264
let s: run_last_options = new_opts
240
265
endfunction
241
266
0 commit comments