diff options
author | hut <hut@lavabit.com> | 2010-03-14 19:38:36 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-03-14 19:38:36 +0100 |
commit | a44749f63848740e95d1f168d73300c874ecf6c5 (patch) | |
tree | 5d22d43c1fa7e71d1c5f6a51c21b0df17907b1c4 /ranger | |
parent | 9341b0d68e0a87e8187fbfa3d6c85cf10f2fe2d1 (diff) | |
download | ranger-a44749f63848740e95d1f168d73300c874ecf6c5.tar.gz |
use `file` for reliably identifying text files
Diffstat (limited to 'ranger')
-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) |