[download]

config/ranger/commands.py

   1 # https://github.com/ranger/ranger/wiki/Custom-Commands#fzf-integration
   2 
   3 import os.path
   4 import subprocess
   5 from ranger.api.commands import Command
   6 
   7 class fzf(Command):
   8     def execute(self):
   9         stdout, stderr = self.fm.execute_command(
  10             'find -L . -print 2>&- | sed "s/^\.$//" | cut -c 3- | fzf',
  11             universal_newlines=True, stdout=subprocess.PIPE
  12         ).communicate()
  13 
  14         if not stdout: return
  15         path = os.path.abspath(stdout.rstrip('\n'))
  16 
  17         if os.path.isdir(path):
  18             self.fm.cd(path)
  19         else:
  20             self.fm.select_file(path)