Esempio n. 1
0
	def _get_mimetype(self, fname):
		# Spawn "file" to determine the mime-type of the given file.
		if self._mimetype:
			return self._mimetype
		mimetype = spawn("file", "--mime-type", "-Lb", fname)
		self._mimetype = mimetype
		return mimetype
Esempio n. 2
0
    def execute(self):
        lastword = self.arg(-1)
        force = lastword == 'force'
        hash_pattern = re.compile(r'^[\d\w]=.')
        entries = spawn('zsh', '-ic', 'hash -d')

        self.fm.bookmarks.update_if_outdated()

        for i in entries.split('\n'):
            if hash_pattern.match(i):
                key, value = i[0], i[2:]
                if force or not key in self.fm.bookmarks.dct.keys():
                    self.fm.bookmarks[key] = Directory(value)
Esempio n. 3
0
 def filetype(self):
     try:
         return spawn(["file", '-Lb', '--mime-type', self.path])
     except OSError:
         return ""
Esempio n. 4
0
 def filetype(self):
     try:
         return spawn(["file", "-Lb", "--mime-type", self.path])
     except OSError:
         return ""
Esempio n. 5
0
import os.path
from ranger.ext.spawn import spawn

# Expand zsh hashes in ranger

vanilla_expand = os.path.expanduser
hashes = [x.split('=') for x in spawn('zsh', '-ic', 'hash -d')[:-1].split('\n')]
hashes = {k: v for (k, v) in hashes}

def zsh_expand(path):
    global hashes

    if len(path) > 1 and path[0] == '~' and path[1] != '/':
        if '/' in path:
            end = path.index('/')
        else:
            end = len(path)
        name = path[1:end]
        if name in hashes:
            return hashes[name] + path[end:]
    return vanilla_expand(path)

os.path.expanduser = zsh_expand