Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion memo.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ hide_deleted=yes
# Display only the latest file from each directory
hide_same_dir=no

# Display only the latest file from each archive
# Does not track nested archives - displays the latest file from only the outermost archive
hide_same_archive=no

# Display the filename of the outermost archive instead of title or inner filename
# Applies to archived files only when hide_same_archive is also enabled
display_archive_name=no

# Date format https://www.lua.org/pil/22.1.html
timestamp_format=%Y-%m-%d %H:%M:%S

Expand Down Expand Up @@ -49,4 +57,4 @@ close_binding=LEFT ESC
# Opening the file "/data/TV Shows/Comedy/Curb Your Enthusiasm/S4/E06.mkv" will
# lead to "Curb Your Enthusiasm" to be shown in the directory menu. Opening
# of that entry will then open that file again.
path_prefixes=pattern:.*
path_prefixes=pattern:.*
63 changes: 45 additions & 18 deletions memo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ local options = {
-- Display only the latest file from each directory
hide_same_dir = false,

-- Display only the latest file from each archive
hide_same_archive = false,

-- If hide_same_archive enabled, display archive filename instead of inner file filename
display_archive_name = false,

-- Date format https://www.lua.org/pil/22.1.html
timestamp_format = "%Y-%m-%d %H:%M:%S",

Expand Down Expand Up @@ -752,7 +758,7 @@ function path_info(full_path)
-- don't resolve magnet-style paths
local protocol_start, protocol_end, protocol = full_path:find("^(%a[%w.+-]-):%?")
if protocol_end then
return full_path, full_path, protocol, true, nil
return full_path, full_path, full_path, protocol, true, nil
end

local display_path, save_path, effective_path, effective_protocol, is_remote, file_options = resolve(nil, nil, full_path, nil, false)
Expand Down Expand Up @@ -838,6 +844,7 @@ function show_history(entries, next_page, prev_page, update, return_items)
local menu_items = {}
local state = (prev_page or next_page) and last_state or {
known_dirs = {},
known_archives = {},
known_files = {},
existing_files = {},
cursor = history:seek("end"),
Expand Down Expand Up @@ -941,6 +948,10 @@ function show_history(entries, next_page, prev_page, update, return_items)
local display_path, save_path, effective_path, effective_protocol, is_remote, file_options = path_info(full_path)
local cache_key = effective_path .. display_path .. (file_options or "")

if options.hide_same_archive and options.display_archive_name and effective_protocol == "archive" then
display_path = effective_path
end

if options.hide_duplicates and state.known_files[cache_key] then
return
end
Expand All @@ -962,26 +973,35 @@ function show_history(entries, next_page, prev_page, update, return_items)
if is_remote then
state.existing_files[cache_key] = true
state.known_files[cache_key] = true
elseif options.hide_same_dir or dir_menu then
dirname, basename = mp.utils.split_path(display_path)
if dir_menu then
if dirname == "." then return end
local unix_dirname = dirname:gsub("\\", "/")
local parent, _ = mp.utils.split_path(unix_dirname:sub(1, -2))
local start, stop = find_path_prefix(parent, dir_menu_prefixes)
if not start then
else
if options.hide_same_archive and effective_protocol == "archive" then
local archive_key = effective_path .. (file_options or "")
if state.known_archives[archive_key] then
return
end
basename = unix_dirname:match("/(.-)/", stop)
if basename == nil then return end
start, stop = dirname:find(basename, stop, true)
dirname = dirname:sub(1, stop + 1)
state.known_archives[archive_key] = true
end
if state.known_dirs[dirname] then
return
end
if dirname ~= "." then
state.known_dirs[dirname] = true
if options.hide_same_dir or dir_menu then
dirname, basename = mp.utils.split_path(display_path)
if dir_menu then
if dirname == "." then return end
local unix_dirname = dirname:gsub("\\", "/")
local parent, _ = mp.utils.split_path(unix_dirname:sub(1, -2))
local start, stop = find_path_prefix(parent, dir_menu_prefixes)
if not start then
return
end
basename = unix_dirname:match("/(.-)/", stop)
if basename == nil then return end
start, stop = dirname:find(basename, stop, true)
dirname = dirname:sub(1, stop + 1)
end
if state.known_dirs[dirname] then
return
end
if dirname ~= "." then
state.known_dirs[dirname] = true
end
end
end

Expand Down Expand Up @@ -1017,6 +1037,10 @@ function show_history(entries, next_page, prev_page, update, return_items)
title = ""
end

if options.hide_same_archive and options.display_archive_name and effective_protocol == "archive" then
title = ""
end

if dir_menu then
title = basename
elseif title == "" then
Expand All @@ -1030,6 +1054,9 @@ function show_history(entries, next_page, prev_page, update, return_items)
if not dirname then
dirname, basename = mp.utils.split_path(effective_display_path)
end
if effective_protocol == "archive" and not options.display_archive_name then
basename = effective_display_path
end
title = basename ~= "" and basename or display_path
if file_options then
title = display_path .. " " .. title
Expand Down