aboutsummaryrefslogtreecommitdiffstats
path: root/fzf-open.lua
diff options
context:
space:
mode:
authorJeeBak Kim <jeebak.kim@gmail.com>2019-12-30 05:57:30 -0800
committerMatěj Cepl <mcepl@cepl.eu>2021-01-16 14:27:05 +0100
commitb466a53bc6ad161161c34b56851541bb8747ff82 (patch)
treec47f8aa8223fa85a0ddfa0075bd8045a393fe880 /fzf-open.lua
parent59c1de462cc0cdaac0e4b57330276b6698227ea5 (diff)
downloadvis-fzf-open-b466a53bc6ad161161c34b56851541bb8747ff82.tar.gz
Cleanup fzf
Diffstat (limited to 'fzf-open.lua')
-rw-r--r--fzf-open.lua46
1 files changed, 37 insertions, 9 deletions
diff --git a/fzf-open.lua b/fzf-open.lua
index 36c4739..8c94cf3 100644
--- a/fzf-open.lua
+++ b/fzf-open.lua
@@ -1,15 +1,15 @@
-- Copyright (C) 2017 Guillaume Chérel
---
+--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Affero General Public License as
-- published by the Free Software Foundation, either version 3 of the
-- License, or (at your option) any later version.
---
+--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU Affero General Public License for more details.
---
+--
-- You should have received a copy of the GNU Affero General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
@@ -18,7 +18,15 @@ module.fzf_path = "fzf"
module.fzf_args = ""
vis:command_register("fzf", function(argv, force, win, selection, range)
- local command = module.fzf_path .. " " .. module.fzf_args .. " " .. table.concat(argv, " ")
+ local command = string.gsub([[
+ $fzf_path $fzf_args $args
+ ]],
+ '%$([%w_]+)', {
+ fzf_path=module.fzf_path,
+ fzf_args=module.fzf_args,
+ args=table.concat(argv, " ")
+ }
+ )
local file = io.popen(command)
local output = file:read()
@@ -28,18 +36,38 @@ vis:command_register("fzf", function(argv, force, win, selection, range)
-- vis:command(string.format("e '%s'", output))
vis:feedkeys(string.format(":e '%s'<Enter>", output))
elseif status == 1 then
- vis:info(string.format("fzf-open: No match. Command %s exited with return value %i." , command, status))
+ vis:info(
+ string.format(
+ "fzf-open: No match. Command %s exited with return value %i.",
+ command, status
+ )
+ )
elseif status == 2 then
- vis:info(string.format("fzf-open: Error. Command %s exited with return value %i." , command, status))
+ vis:info(
+ string.format(
+ "fzf-open: Error. Command %s exited with return value %i.",
+ command, status
+ )
+ )
elseif status == 130 then
- vis:info(string.format("fzf-open: Interrupted. Command %s exited with return value %i" , command, status))
+ vis:info(
+ string.format(
+ "fzf-open: Interrupted. Command %s exited with return value %i",
+ command, status
+ )
+ )
else
- vis:info(string.format("fzf-open: Unknown exit status %i. command %s exited with return value %i" , status, command, status, status))
+ vis:info(
+ string.format(
+ "fzf-open: Unknown exit status %i. command %s exited with return value %i",
+ status, command, status
+ )
+ )
end
vis:feedkeys("<vis-redraw>")
return true;
-end)
+end, "Select file to open with fzf")
return module