Skip to content

Commit

Permalink
fix: edit files actions on path containing whitespaces for fd/find/ez…
Browse files Browse the repository at this point in the history
…a/ls results (#258)

* fix: edit action on fd/find results

* test: fzfx.actions.make_edit

* chore: PR template

* perf: remove dead code

* lint: typecheck

* fix: edit file explorer actions

* feat: provide edit_buffers/edit_git_files

* doc: format

* refactor(actions): deprecate 'edit' actions
  • Loading branch information
linrongbin16 authored Oct 9, 2023
1 parent cf0e536 commit 2a2c1a9
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 148 deletions.
2 changes: 0 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Thanks to your contribute, while please finish below tasks:

# Regresion test

## Platform
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,11 @@ Install with the below 3 options:

<img alt="install-windows-git1.png" src="https://raw.githubusercontent.com/linrongbin16/lin.nvim.dev/main/assets/installations/install-windows-git1.png" width="70%" />

- In **Adjusting your PATH environment**, select **Use Git and optional Unix tools
from the Command Prompt**.
- In **Adjusting your PATH environment**, select **Use Git and optional Unix tools from the Command Prompt**.

<img alt="install-windows-git2.png" src="https://raw.githubusercontent.com/linrongbin16/lin.nvim.dev/main/assets/installations/install-windows-git2.png" width="70%" />

- In **Configuring the terminal emulator to use with Git Bash**, select **Use Windows's
default console window**.
- In **Configuring the terminal emulator to use with Git Bash**, select **Use Windows's default console window**.

<img alt="install-windows-git3.png" src="https://raw.githubusercontent.com/linrongbin16/lin.nvim.dev/main/assets/installations/install-windows-git3.png" width="70%" />

Expand Down Expand Up @@ -213,7 +211,7 @@ require("lazy").setup({
{ "junegunn/fzf", build = ":call fzf#install()" },
{
"linrongbin16/fzfx.nvim",
dependencies = { "junegunn/fzf" },
dependencies = { "junegunn/fzf", "nvim-tree/nvim-web-devicons" },
config = function()
require("fzfx").setup()
end
Expand Down
57 changes: 56 additions & 1 deletion lua/fzfx/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,49 @@ local function make_edit(delimiter, file_pos, lineno_pos, colno_pos)
return impl
end

--- @alias EditFindVimCommands {edit:string[]}
--- @param lines string[]
--- @param opts {no_icon:boolean?}?
--- @return EditFindVimCommands
local function make_edit_find_commands(lines, opts)
local results = { edit = {} }
for i, line in ipairs(lines) do
local filename = line_helpers.parse_find(line, opts)
local edit_command = string.format("edit %s", filename)
table.insert(results.edit, edit_command)
end
return results
end

-- Run 'edit' vim command on fd/find results.
--- @param lines string[]
local function edit_find(lines)
local vim_commands = make_edit_find_commands(lines)
for i, edit_command in ipairs(vim_commands.edit) do
log.debug("|fzfx.actions - edit_find| [%d]:[%s]", i, edit_command)
vim.cmd(edit_command)
end
end

-- Run 'edit' vim command on buffers results.
--- @param lines string[]
local function edit_buffers(lines)
return edit_find(lines)
end

-- Run 'edit' vim command on git files results.
--- @param lines string[]
local function edit_git_files(lines)
return edit_find(lines)
end

--- @deprecated
--- @param lines string[]
local function edit(lines)
return make_edit()(lines)
require("fzfx.deprecated").notify(
"deprecated 'actions.edit', please use 'actions.edit_find'!"
)
return edit_find(lines)
end

local function edit_rg(lines)
Expand All @@ -114,6 +154,16 @@ local function edit_grep(lines)
return make_edit(":", 1, 2)(lines)
end

-- Run 'edit' vim command on eza/exa/ls results.
--- @param lines string[]
local function edit_ls(lines)
local vim_commands = make_edit_find_commands(lines, { no_icon = true })
for i, edit_command in ipairs(vim_commands.edit) do
log.debug("|fzfx.actions - edit_ls| [%d]:[%s]", i, edit_command)
vim.cmd(edit_command)
end
end

local function buffer(lines)
return make_edit()(lines)
end
Expand Down Expand Up @@ -177,7 +227,12 @@ local M = {
nop = nop,
make_edit_vim_commands = make_edit_vim_commands,
make_edit = make_edit,
make_edit_find_commands = make_edit_find_commands,
edit = edit,
edit_find = edit_find,
edit_buffers = edit_buffers,
edit_git_files = edit_git_files,
edit_ls = edit_ls,
edit_rg = edit_rg,
edit_grep = edit_grep,
buffer = buffer,
Expand Down
Loading

0 comments on commit 2a2c1a9

Please sign in to comment.