@@ -93,42 +93,53 @@ function M.throttle(ms, fn)
93
93
end
94
94
end
95
95
96
- --- @class LazyCmdOpts
96
+ --- @class LazyCmdOptions : LazyFloatOptions
97
97
--- @field cwd ? string
98
98
--- @field env ? table<string,string>
99
99
--- @field float ? LazyFloatOptions
100
100
101
- --- @param cmd string[]
102
- --- @param opts ? { cwd : string , filetype : string , terminal ?: boolean , close_on_exit ?: boolean , enter ?: boolean , float ?: LazyFloatOptions }
103
- function M .open_cmd (cmd , opts )
101
+ -- Opens a floating terminal (interactive by default)
102
+ --- @param cmd ? string[] | string
103
+ --- @param opts ? LazyCmdOptions |{ interactive ?: boolean }
104
+ function M .float_term (cmd , opts )
105
+ cmd = cmd or {}
106
+ if type (cmd ) == " string" then
107
+ cmd = { cmd }
108
+ end
109
+ if # cmd == 0 then
110
+ cmd = { vim .env .SHELL or vim .o .shell }
111
+ end
104
112
opts = opts or {}
105
- local float = M .float (opts .float )
113
+ local float = M .float (opts )
114
+ vim .fn .termopen (cmd , vim .tbl_isempty (opts ) and vim .empty_dict () or opts )
115
+ if opts .interactive ~= false then
116
+ vim .cmd .startinsert ()
117
+ vim .api .nvim_create_autocmd (" TermClose" , {
118
+ once = true ,
119
+ buffer = float .buf ,
120
+ callback = function ()
121
+ float :close ()
122
+ vim .cmd .checktime ()
123
+ end ,
124
+ })
125
+ end
126
+ return float
127
+ end
106
128
129
+ --- Runs the command and shows it in a floating window
130
+ --- @param cmd string[]
131
+ --- @param opts ? LazyCmdOptions |{ filetype ?: string }
132
+ function M .float_cmd (cmd , opts )
133
+ opts = opts or {}
134
+ local float = M .float (opts )
107
135
if opts .filetype then
108
136
vim .bo [float .buf ].filetype = opts .filetype
109
137
end
110
- if opts .terminal then
111
- opts .terminal = nil
112
- vim .fn .termopen (cmd , opts )
113
- if opts .enter then
114
- vim .cmd .startinsert ()
115
- end
116
- if opts .close_on_exit then
117
- vim .api .nvim_create_autocmd (" TermClose" , {
118
- once = true ,
119
- buffer = float .buf ,
120
- callback = function ()
121
- float :close ()
122
- vim .cmd .checktime ()
123
- end ,
124
- })
125
- end
126
- else
127
- local Process = require (" lazy.manage.process" )
128
- local lines = Process .exec (cmd , { cwd = opts .cwd })
129
- vim .api .nvim_buf_set_lines (float .buf , 0 , - 1 , false , lines )
130
- vim .bo [float .buf ].modifiable = false
131
- end
138
+ local Process = require (" lazy.manage.process" )
139
+ local lines = Process .exec (cmd , { cwd = opts .cwd })
140
+ vim .api .nvim_buf_set_lines (float .buf , 0 , - 1 , false , lines )
141
+ vim .bo [float .buf ].modifiable = false
142
+ return float
132
143
end
133
144
134
145
--- @return string ?
0 commit comments