about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--doc/ranger.110
-rw-r--r--doc/ranger.pod6
-rw-r--r--ranger/config/rc.conf2
-rw-r--r--ranger/container/fsobject.py4
-rw-r--r--ranger/core/linemode.py27
-rw-r--r--ranger/ext/human_readable.py16
6 files changed, 61 insertions, 4 deletions
diff --git a/doc/ranger.1 b/doc/ranger.1
index 32df615e..43a13659 100644
--- a/doc/ranger.1
+++ b/doc/ranger.1
@@ -129,7 +129,7 @@
 .\" ========================================================================
 .\"
 .IX Title "RANGER 1"
-.TH RANGER 1 "ranger-1.9.2" "2019-04-03" "ranger manual"
+.TH RANGER 1 "ranger-1.9.2" "2019-04-23" "ranger manual"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
@@ -1297,10 +1297,16 @@ Flags:
 .IX Item "linemode linemodename"
 Sets the linemode of all files in the current directory.  The linemode may be:
 .Sp
-.Vb 6
+.Vb 12
 \& "filename": display each line as "<basename>...<size>"
 \& "fileinfo": display each line as "<basename>...<file(1) output>"
+\& "mtime": display each line as "<basename>...<mtime>" in ISO format
+\& "humanreadablemtime": display each line as "<basename>...<mtime>" in a human
+\&     readable format, more precise the more recent
 \& "permissions": display each line as "<permissions> <owner> <group> <basename>"
+\& "sizemtime": display each line as "<basename>...<size> <mtime>" in ISO format
+\& "humanreadablesizemtime": display each line as "<basename>...<size> <mtime>"
+\&     in a human readable format, more precise the more recent
 \& "metatitle": display metadata from .metadata.json files if
 \&     available, fall back to the "filename" linemode if no
 \&     metadata was found.  See :meta command.
diff --git a/doc/ranger.pod b/doc/ranger.pod
index a89670f3..d182f3af 100644
--- a/doc/ranger.pod
+++ b/doc/ranger.pod
@@ -1387,7 +1387,13 @@ Sets the linemode of all files in the current directory.  The linemode may be:
 
  "filename": display each line as "<basename>...<size>"
  "fileinfo": display each line as "<basename>...<file(1) output>"
+ "mtime": display each line as "<basename>...<mtime>" in ISO format
+ "humanreadablemtime": display each line as "<basename>...<mtime>" in a human
+     readable format, more precise the more recent
  "permissions": display each line as "<permissions> <owner> <group> <basename>"
+ "sizemtime": display each line as "<basename>...<size> <mtime>" in ISO format
+ "humanreadablesizemtime": display each line as "<basename>...<size> <mtime>"
+     in a human readable format, more precise the more recent
  "metatitle": display metadata from .metadata.json files if
      available, fall back to the "filename" linemode if no
      metadata was found.  See :meta command.
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index 4a182f69..f559290d 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -371,8 +371,10 @@ map <C-p> chain console; eval fm.ui.console.history_move(-1)
 map Mf linemode filename
 map Mi linemode fileinfo
 map Mm linemode mtime
+map Mh linemode humanreadablemtime
 map Mp linemode permissions
 map Ms linemode sizemtime
+map MH linemode sizehumanreadablemtime
 map Mt linemode metatitle
 
 # Tagging / Marking
diff --git a/ranger/container/fsobject.py b/ranger/container/fsobject.py
index f57fb451..4fb47354 100644
--- a/ranger/container/fsobject.py
+++ b/ranger/container/fsobject.py
@@ -13,6 +13,7 @@ from time import time
 from ranger.core.linemode import (
     DEFAULT_LINEMODE, DefaultLinemode, TitleLinemode,
     PermissionsLinemode, FileInfoLinemode, MtimeLinemode, SizeMtimeLinemode,
+    HumanReadableMtimeLinemode, SizeHumanReadableMtimeLinemode
 )
 from ranger.core.shared import FileManagerAware, SettingsAware
 from ranger.ext.shell_escape import shell_escape
@@ -93,7 +94,8 @@ class FileSystemObject(  # pylint: disable=too-many-instance-attributes,too-many
     linemode_dict = dict(
         (linemode.name, linemode()) for linemode in
         [DefaultLinemode, TitleLinemode, PermissionsLinemode, FileInfoLinemode,
-         MtimeLinemode, SizeMtimeLinemode]
+         MtimeLinemode, SizeMtimeLinemode, HumanReadableMtimeLinemode,
+         SizeHumanReadableMtimeLinemode]
     )
 
     def __init__(self, path, preload=None, path_is_abs=False, basename_is_rel_to=None):
diff --git a/ranger/core/linemode.py b/ranger/core/linemode.py
index 3a29b552..48da3509 100644
--- a/ranger/core/linemode.py
+++ b/ranger/core/linemode.py
@@ -7,7 +7,7 @@ from __future__ import (absolute_import, division, print_function)
 
 from abc import ABCMeta, abstractproperty, abstractmethod
 from datetime import datetime
-from ranger.ext.human_readable import human_readable
+from ranger.ext.human_readable import human_readable, human_readable_time
 from ranger.ext import spawn
 
 DEFAULT_LINEMODE = "filename"
@@ -131,3 +131,28 @@ class SizeMtimeLinemode(LinemodeBase):
             return '?'
         return "%s %s" % (human_readable(fobj.size),
                           datetime.fromtimestamp(fobj.stat.st_mtime).strftime("%Y-%m-%d %H:%M"))
+
+
+class HumanReadableMtimeLinemode(LinemodeBase):
+    name = "humanreadablemtime"
+
+    def filetitle(self, fobj, metadata):
+        return fobj.relative_path
+
+    def infostring(self, fobj, metadata):
+        if fobj.stat is None:
+            return '?'
+        return human_readable_time(fobj.stat.st_mtime)
+
+
+class SizeHumanReadableMtimeLinemode(LinemodeBase):
+    name = "sizehumanreadablemtime"
+
+    def filetitle(self, fobj, metadata):
+        return fobj.relative_path
+
+    def infostring(self, fobj, metadata):
+        if fobj.stat is None:
+            return '?'
+        size = human_readable(fobj.size)
+        return "%s %11s" % (size, human_readable_time(fobj.stat.st_mtime))
diff --git a/ranger/ext/human_readable.py b/ranger/ext/human_readable.py
index 848f4255..44f23079 100644
--- a/ranger/ext/human_readable.py
+++ b/ranger/ext/human_readable.py
@@ -3,6 +3,7 @@
 
 from __future__ import (absolute_import, division, print_function)
 
+from datetime import datetime
 from ranger.core.shared import SettingsAware
 
 
@@ -54,6 +55,21 @@ def human_readable(byte, separator=' '):  # pylint: disable=too-many-return-stat
     return '>9000'
 
 
+def human_readable_time(timestamp):
+    """Convert a timestamp to an easily readable format.
+    """
+    # Hard to test because it's relative to ``now()``
+    date = datetime.fromtimestamp(timestamp)
+    datediff = datetime.now().date() - date.date()
+    if datediff.days >= 365:
+        return date.strftime("%-d %b %Y")
+    elif datediff.days >= 7:
+        return date.strftime("%-d %b")
+    elif datediff.days >= 1:
+        return date.strftime("%a")
+    return date.strftime("%H:%M")
+
+
 if __name__ == '__main__':
 
     # XXX: This mock class is a temporary (as of 2019-01-27) hack.