150
150
--- Get the oil url for a given directory
151
151
--- @private
152
152
--- @param dir nil | string When nil , use the cwd
153
- --- @return nil | string The parent url
153
+ --- @param use_oil_parent nil | boolean If in an oil buffer , return the parent (default true )
154
+ --- @return string The parent url
154
155
--- @return nil | string The basename (if present ) of the file /dir we were just in
155
- M .get_url_for_path = function (dir )
156
+ M .get_url_for_path = function (dir , use_oil_parent )
157
+ if use_oil_parent == nil then
158
+ use_oil_parent = true
159
+ end
156
160
local config = require (" oil.config" )
157
161
local fs = require (" oil.fs" )
158
162
local util = require (" oil.util" )
@@ -169,15 +173,16 @@ M.get_url_for_path = function(dir)
169
173
return config .adapter_to_scheme .files .. path
170
174
else
171
175
local bufname = vim .api .nvim_buf_get_name (0 )
172
- return M .get_buffer_parent_url (bufname )
176
+ return M .get_buffer_parent_url (bufname , use_oil_parent )
173
177
end
174
178
end
175
179
176
180
--- @private
177
181
--- @param bufname string
182
+ --- @param use_oil_parent boolean If in an oil buffer , return the parent
178
183
--- @return string
179
184
--- @return nil | string
180
- M .get_buffer_parent_url = function (bufname )
185
+ M .get_buffer_parent_url = function (bufname , use_oil_parent )
181
186
local config = require (" oil.config" )
182
187
local fs = require (" oil.fs" )
183
188
local pathutil = require (" oil.pathutil" )
@@ -202,6 +207,9 @@ M.get_buffer_parent_url = function(bufname)
202
207
return config .adapter_to_scheme .files .. util .addslash (path )
203
208
end
204
209
210
+ if not use_oil_parent then
211
+ return bufname
212
+ end
205
213
local adapter = config .get_adapter_by_scheme (scheme )
206
214
local parent_url
207
215
if adapter and adapter .get_parent then
@@ -834,6 +842,7 @@ M.setup = function(opts)
834
842
config .setup (opts )
835
843
set_colors ()
836
844
vim .api .nvim_create_user_command (" Oil" , function (args )
845
+ local util = require (" oil.util" )
837
846
if args .smods .tab == 1 then
838
847
vim .cmd .tabnew ()
839
848
end
@@ -864,7 +873,9 @@ M.setup = function(opts)
864
873
local method = float and " open_float" or " open"
865
874
local path = args .fargs [1 ]
866
875
if trash then
867
- path = " oil-trash:///"
876
+ local url = M .get_url_for_path (path , false )
877
+ local _ , new_path = util .parse_url (url )
878
+ path = " oil-trash://" .. new_path
868
879
end
869
880
M [method ](path )
870
881
end , { desc = " Open oil file browser on a directory" , nargs = " *" , complete = " dir" })
0 commit comments