diff options
-rw-r--r-- | ranger/defaults/apps.py | 5 | ||||
-rw-r--r-- | ranger/fsobject/fsobject.py | 11 |
2 files changed, 15 insertions, 1 deletions
diff --git a/ranger/defaults/apps.py b/ranger/defaults/apps.py index 7e522df9..01f11f24 100644 --- a/ranger/defaults/apps.py +++ b/ranger/defaults/apps.py @@ -80,9 +80,12 @@ class CustomApplications(Applications): if f.image: return self.either(c, 'feh', 'eye_of_gnome', 'mirage') - if f.document: + if f.document or f.filetype.startswith('text'): return self.app_editor(c) + raise Exception(f.filetype) + + # ----------------------------------------- application definitions def app_pager(self, c): return tup('less', *c) diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py index 80ce1e48..8ad6d489 100644 --- a/ranger/fsobject/fsobject.py +++ b/ranger/fsobject/fsobject.py @@ -30,6 +30,7 @@ class FileSystemObject(MimeTypeAware, FileManagerAware): basename = None basename_lower = None _shell_escaped_basename = None + _filetype = None dirname = None extension = None exists = False @@ -86,6 +87,16 @@ class FileSystemObject(MimeTypeAware, FileManagerAware): self._shell_escaped_basename = shell_escape(self.basename) return self._shell_escaped_basename + @property + def filetype(self): + if self._filetype is None: + import subprocess + got = subprocess.Popen(["file", '-Lb', '--mime-type', self.path],\ + stdout=subprocess.PIPE) \ + .communicate()[0] + self._filetype = got + return self._filetype + def get_description(self): return "Loading " + str(self) |