diff options
author | hut <hut@lavabit.com> | 2010-10-01 22:12:57 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-10-01 22:12:57 +0200 |
commit | 9e7c69a8879e63a0a661127d9d6aa21e0ef594a9 (patch) | |
tree | cec9ca6143cb99148bfdcf9cbc941ea656d47afb /ranger/fsobject/directory.py | |
parent | 2d98e85fddaefbc6074336d7d90925f7f7f936b0 (diff) | |
download | ranger-9e7c69a8879e63a0a661127d9d6aa21e0ef594a9.tar.gz |
fsobject.directory: added numerical sort
Diffstat (limited to 'ranger/fsobject/directory.py')
-rw-r--r-- | ranger/fsobject/directory.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py index 9bdb4caa..ab12734f 100644 --- a/ranger/fsobject/directory.py +++ b/ranger/fsobject/directory.py @@ -15,6 +15,7 @@ import os.path import stat +import re from stat import S_ISLNK, S_ISDIR from os import stat as os_stat, lstat as os_lstat from os.path import join, isdir, basename @@ -39,6 +40,18 @@ def sort_by_directory(path): """returns 0 if path is a directory, otherwise 1 (for sorting)""" return 1 - path.is_directory +def sort_by_number(path): + try: + return float(re.search(r'\d+', path.basename).group(0)) + except: + return path.basename + +def sort_by_number_icase(path): + try: + return float(re.search(r'\d+', path.basename).group(0)) + except: + return path.basename_lower + def accept_file(fname, hidden_filter, name_filter): if hidden_filter: try: @@ -76,6 +89,7 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): sort_dict = { 'basename': sort_by_basename, + 'numeric': sort_by_number, 'size': lambda path: -path.size, 'mtime': lambda path: -(path.stat and path.stat.st_mtime or 1), 'type': lambda path: path.mimetype, @@ -295,6 +309,10 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): sort_func == sort_by_basename: sort_func = sort_by_basename_icase + if self.settings.sort_case_insensitive and \ + sort_func == sort_by_number: + sort_func = sort_by_number_icase + self.files.sort(key = sort_func) if self.settings.sort_reverse: |