diff options
-rw-r--r-- | ranger/defaults/keys.py | 3 | ||||
-rw-r--r-- | ranger/defaults/options.py | 1 | ||||
-rw-r--r-- | ranger/fsobject/directory.py | 14 | ||||
-rw-r--r-- | ranger/shared/settings.py | 1 |
4 files changed, 17 insertions, 2 deletions
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py index bdafb4af..e021a90e 100644 --- a/ranger/defaults/keys.py +++ b/ranger/defaults/keys.py @@ -108,13 +108,14 @@ def initialize_commands(map): # -------------------------------------------------- toggle options map('b', hint="show_//h//idden //p//review_files //d//irectories_first " \ - "//c//ollapse_preview flush//i//nput") + "//c//ollapse_preview flush//i//nput ca//s//e_insensitive") map('bh', fm.toggle_boolean_option('show_hidden')) map('bp', fm.toggle_boolean_option('preview_files')) map('bP', fm.toggle_boolean_option('preview_directories')) map('bi', fm.toggle_boolean_option('flushinput')) map('bd', fm.toggle_boolean_option('directories_first')) map('bc', fm.toggle_boolean_option('collapse_preview')) + map('bs', fm.toggle_boolean_option('case_insensitive')) # ------------------------------------------------------------ sort map('o', 'O', hint="//s//ize //b//ase//n//ame //m//time //t//ype //r//everse") diff --git a/ranger/defaults/options.py b/ranger/defaults/options.py index a7090285..e41faf2f 100644 --- a/ranger/defaults/options.py +++ b/ranger/defaults/options.py @@ -81,5 +81,6 @@ show_cursor = False # One of: size, basename, mtime, type sort = 'basename' reverse = False +case_insensitive = False directories_first = True diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py index 8bb8a78a..3ef897e0 100644 --- a/ranger/fsobject/directory.py +++ b/ranger/fsobject/directory.py @@ -27,6 +27,10 @@ def sort_by_basename(path): """returns path.basename (for sorting)""" return path.basename +def sort_by_basename_icase(path): + """returns case-insensitive path.basename (for sorting)""" + return path.basename.lower() + def sort_by_directory(path): """returns 0 if path is a directory, otherwise 1 (for sorting)""" return 1 - int( isinstance( path, Directory ) ) @@ -86,6 +90,7 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): self.old_filter = self.filter self.old_hidden_filter = self.settings.hidden_filter self.old_reverse = self.settings.reverse + self.old_case_insensitive = self.settings.case_insensitive def get_list(self): return self.files @@ -265,6 +270,11 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): sort_func = self.sort_dict[self.settings.sort] except: sort_func = sort_by_basename + + if self.settings.case_insensitive and \ + sort_func == sort_by_basename: + sort_func = sort_by_basename_icase + self.files.sort(key = sort_func) if self.settings.reverse: @@ -281,12 +291,14 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): self.old_directories_first = self.settings.directories_first self.old_sort = self.settings.sort self.old_reverse = self.settings.reverse + self.old_case_insensitive = self.settings.case_insensitive def sort_if_outdated(self): """Sort the containing files if they are outdated""" if self.old_directories_first != self.settings.directories_first \ or self.old_sort != self.settings.sort \ - or self.old_reverse != self.settings.reverse: + or self.old_reverse != self.settings.reverse \ + or self.old_case_insensitive != self.settings.case_insensitive: self.sort() return True return False diff --git a/ranger/shared/settings.py b/ranger/shared/settings.py index cdddd623..991f77d2 100644 --- a/ranger/shared/settings.py +++ b/ranger/shared/settings.py @@ -28,6 +28,7 @@ ALLOWED_SETTINGS = { 'draw_borders': bool, 'sort': str, 'reverse': bool, + 'case_insensitive': bool, 'directories_first': bool, 'update_title': bool, 'shorten_title': int, # Note: False is an instance of int |