Skip to content

Instantly share code, notes, and snippets.

@yat1ma30
Forked from rupeshtr78/fzf_history.lua
Created March 11, 2024 01:30
Show Gist options
  • Save yat1ma30/619a3ac179770ef589f6650c6651775d to your computer and use it in GitHub Desktop.
Save yat1ma30/619a3ac179770ef589f6650c6651775d to your computer and use it in GitHub Desktop.
Windows FZF history search with cmder ,clink
-- fzf clink history search
-- update cmder\vendor\clink >= clink -- version = 1.1.44
-- install fzf choco install fzf
-- add the fzf_history.lua to cmder\config folder
-- add below key binding to _inputrc use "clink info" to find inputrc path
-- M-x: "luafunc:fzf_history" #Alt x
-- Might have to adjust your regex in line 38 39 based on your settings
-- reference https://chrisant996.github.io/clink/clink.html
settings.add("fzf.height", "40%", "Height to use for the --height flag")
-- settings.add("fzf.exe_location", "", "Location of fzf.exe if not on the PATH")
-- Build a command line to pipe history and launch fzf
local function get_fzf()
local height = settings.get("fzf.height")
local c = "C:\\cmder\\vendor\\clink\\clink_x64.exe"
local session_history = c.." --session".." clink.getsession()".. " history".." --bare"
local fzf_command= session_history.." | ".."fzf"
if height and height ~= "" then
fzf_command = fzf_command..' --height '..height..' --layout=reverse'
end
return fzf_command
end
local fzf_complete_intercept = false
function fzf_history(rl_buffer)
print("Searching History")
fzf_complete_intercept = true
if not fzf_complete_intercept then
return
end
local handle = io.popen(get_fzf())
local result = handle:read("*a")
handle:close()
if fzf_complete_intercept then
for hist in string.gmatch(result, "(.+)$") do
rl_buffer:insert(hist)
end
end
fzf_complete_intercept = false
rl_buffer:refreshline()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment