awful: fix empty command adding

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Damien Leone 2008-08-11 20:39:03 +02:00 committed by Julien Danjou
parent df7d60faf3
commit 2e4fdbb40d
1 changed files with 14 additions and 11 deletions

View File

@ -779,7 +779,7 @@ end
--- Set path for history file --- Set path for history file
-- @param path The history file path, set "on" to enable history in the default file (~/.awesome_history) -- @param path The history file path, set "on" to enable history in the default file (~/.awesome_history)
-- @param max_size Optional parameter: set the max entries number in the history file, 50 by default -- @param max_cmd Optional parameter: set the max entries number in the history file, 50 by default
function prompt.history.set(path, max_cmd) function prompt.history.set(path, max_cmd)
if path then if path then
prompt.history.data.path = path prompt.history.data.path = path
@ -809,19 +809,20 @@ end
--- Add an entry to the history file --- Add an entry to the history file
-- @param command The command to add -- @param command The command to add
local function prompt_history_add(command) local function prompt_history_add(command)
if prompt.history.data.path if prompt.history.data.path then
and command if command ~= ""
and command ~= prompt.history.data.table[#prompt.history.data.table] then and command ~= prompt.history.data.table[#prompt.history.data.table] then
table.insert(prompt.history.data.table, command) table.insert(prompt.history.data.table, command)
-- Do not exceed our max_cmd -- Do not exceed our max_cmd
if #prompt.history.data.table > prompt.history.data.max then if #prompt.history.data.table > prompt.history.data.max then
table.remove(prompt.history.data.table, 1) table.remove(prompt.history.data.table, 1)
end
-- Save table content in file, not very optimized atm...
prompt_history_save()
end end
-- Save table content in file, not very optimized atm...
prompt_history_save()
prompt.history.data.index = #prompt.history.data.table + 1 prompt.history.data.index = #prompt.history.data.table + 1
end end
end end
@ -1055,6 +1056,8 @@ function prompt.run(args, textbox, exe_callback, completion_callback)
command = prompt.history.data.table[prompt.history.data.index] command = prompt.history.data.table[prompt.history.data.index]
cur_pos = #command + 2 cur_pos = #command + 2
elseif prompt.history.data.index == #prompt.history.data.table then elseif prompt.history.data.index == #prompt.history.data.table then
prompt.history.data.index = prompt.history.data.index + 1
command = "" command = ""
cur_pos = 1 cur_pos = 1
end end