Skip to content

Commit

Permalink
feat: case insensitive sorting (#429)
Browse files Browse the repository at this point in the history
* check for sorting option in netrw

* documentation

* refactor: remove sort_ prefix

---------

Co-authored-by: Steven Arcangeli <[email protected]>
  • Loading branch information
PhilippOesch and stevearc authored Jul 1, 2024
1 parent c7c7ce5 commit 2077cc3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ require("oil").setup({
-- Sort file names in a more intuitive order for humans. Is less performant,
-- so you may want to set to false if you work with large directories.
natural_order = true,
-- Sort file and directory names case insensitive
case_insensitive = false,
sort = {
-- sort order can be "asc" or "desc"
-- see :help oil-columns to see which columns are sortable
Expand Down
2 changes: 2 additions & 0 deletions doc/oil.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ CONFIG *oil-confi
-- Sort file names in a more intuitive order for humans. Is less performant,
-- so you may want to set to false if you work with large directories.
natural_order = true,
-- Sort file and directory names case insensitive
case_insensitive = false,
sort = {
-- sort order can be "asc" or "desc"
-- see :help oil-columns to see which columns are sortable
Expand Down
12 changes: 9 additions & 3 deletions lua/oil/columns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,17 @@ M.register("name", {
end,

get_sort_value = function(entry)
local sort_value = entry[FIELD_NAME]

if config.view_options.natural_order then
return entry[FIELD_NAME]:gsub("%d+", pad_number)
else
return entry[FIELD_NAME]
sort_value = sort_value:gsub("%d+", pad_number)
end

if config.view_options.case_insensitive then
sort_value = sort_value:lower()
end

return sort_value
end,
})

Expand Down
2 changes: 2 additions & 0 deletions lua/oil/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ local default_config = {
-- Sort file names in a more intuitive order for humans. Is less performant,
-- so you may want to set to false if you work with large directories.
natural_order = true,
-- Sort file and directory names case insensitive
case_insensitive = false,
sort = {
-- sort order can be "asc" or "desc"
-- see :help oil-columns to see which columns are sortable
Expand Down

0 comments on commit 2077cc3

Please sign in to comment.