Skip to content

Commit

Permalink
fix: escape spaces in paths for grug-far integration (#267)
Browse files Browse the repository at this point in the history
This change allows the grug-far integration to work with paths that
contain spaces. It escapes spaces in the path before passing it to
grug-far.

This was suggested by @MagicDuck in
be2ac43

👍🏻👍🏻
  • Loading branch information
mikavilpas authored Jul 26, 2024
1 parent a5f607e commit f265e95
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lua/yazi/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function M.default()
local filter = directory:make_relative(vim.uv.cwd())
require('grug-far').grug_far({
prefills = {
paths = filter,
paths = filter:gsub(' ', '\\ '),
},
})
end,
Expand Down
27 changes: 27 additions & 0 deletions spec/yazi/grug_far_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---@module "plenary.path"

local assert = require('luassert')
local mock = require('luassert.mock')
local config = require('yazi.config')
local plenary_path = require('plenary.path')

describe('the grug-far integration (search and replace)', function()
local mock_grug_far = { grug_far = function() end }

before_each(function()
mock.revert(mock_grug_far)
package.loaded['grug-far'] = mock(mock_grug_far)
end)

it('opens yazi with the current file selected', function()
local tmp_path = plenary_path:new('/tmp/folder with spaces/')

config.default().integrations.replace_in_directory(tmp_path)

assert.spy(mock_grug_far.grug_far).was_called_with({
prefills = {
paths = '/tmp/folder\\ with\\ spaces',
},
})
end)
end)

0 comments on commit f265e95

Please sign in to comment.