Sorry, forgot the attachment :(
On Mon, Oct 24, 2011 at 6:58 PM, Massimiliano Brocchini < [email protected]> wrote: > Hi, > > another patch to prompt.lua; this one allows users to search in the history > writing some text in the prompt and the using CTRL+r/s to search > backward/forward. > Users can use CTRL+Up/Down to search backward/forward for entries beginning > with the text written in the prompt (i.e. there is a search for > '^'..command). For ZSH users this is similar to up-line-or-search. > > Massimiliano >
From 0f27527f6ee2d5cefe7e4774e3bdf127c7694e57 Mon Sep 17 00:00:00 2001 From: Massimiliano Brocchini <[email protected]> Date: Mon, 24 Oct 2011 18:54:55 +0200 Subject: [PATCH 2/2] search in prompt history Signed-off-by: Massimiliano Brocchini <[email protected]> --- :100644 100644 d953569... 6bbd3ea... M lib/awful/prompt.lua.in lib/awful/prompt.lua.in | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 47 insertions(+), 0 deletions(-) diff --git a/lib/awful/prompt.lua.in b/lib/awful/prompt.lua.in index d953569..6bbd3ea 100644 --- a/lib/awful/prompt.lua.in +++ b/lib/awful/prompt.lua.in @@ -26,6 +26,13 @@ module("awful.prompt") local data = {} data.history = {} +local search_term = nil +local function itera (inc,a, i) + i = i + inc + local v = a[i] + if v then return i,v end +end + -- Load history file in history table -- @param id The data.history identifier which is the path to the filename -- @param max Optional parameter, the maximum number of entries in file @@ -165,6 +172,8 @@ function run(args, textbox, exe_callback, completion_callback, history_path, his local font = args.font or theme.font local selectall = args.selectall + search_term=nil + history_check_load(history_path, history_max) local history_index = history_items(history_path) + 1 -- The cursor position @@ -224,6 +233,26 @@ function run(args, textbox, exe_callback, completion_callback, history_path, his end elseif key == "e" then cur_pos = #command + 1 + elseif key == "r" then + search_term = search_term or command:sub(1, cur_pos - 1) + for i,v in (function(a,i) return itera(-1,a,i) end), data.history[history_path].table, history_index do + if v:find(search_term) ~= nil then + command=v + history_index=i + cur_pos=#command+1 + break + end + end + elseif key == "s" then + search_term = search_term or command:sub(1, cur_pos - 1) + for i,v in (function(a,i) return itera(1,a,i) end), data.history[history_path].table, history_index do + if v:find(search_term) ~= nil then + command=v + history_index=i + cur_pos=#command+1 + break + end + end elseif key == "f" then if cur_pos <= #command then cur_pos = cur_pos + 1 @@ -238,6 +267,24 @@ function run(args, textbox, exe_callback, completion_callback, history_path, his elseif key == "u" then command = command:sub(cur_pos, #command) cur_pos = 1 + elseif key == "Up" then + search_term = search_term or command:sub(1, cur_pos - 1) + for i,v in (function(a,i) return itera(-1,a,i) end), data.history[history_path].table, history_index do + if v:find('^'..search_term) ~= nil then + command=v + history_index=i + break + end + end + elseif key == "Down" then + search_term = search_term or command:sub(1, cur_pos - 1) + for i,v in (function(a,i) return itera(1,a,i) end), data.history[history_path].table, history_index do + if v:find('^'..search_term) ~= nil then + command=v + history_index=i + break + end + end elseif key == "w" or key == "BackSpace" then local wstart = 1 local wend = 1 -- 1.7.7
