1from ranger.api.commands import Command
2
3class paste_as_root(Command):
4 def execute(self):
5 if self.fm.do_cut:
6 self.fm.execute_console('shell sudo mv %c .')
7 else:
8 self.fm.execute_console('shell sudo cp -r %c .')
9
10class fzf_select(Command):
11 """
12 :fzf_select
13
14 Find a file using fzf.
15
16 With a prefix argument select only directories.
17
18 See: https://github.com/junegunn/fzf
19 """
20 def execute(self):
21 import subprocess
22 import os.path
23 if self.quantifier:
24 # match only directories
25 command="find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
26 -o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf +m --reverse --header='Jump to file'"
27 else:
28 # match files and directories
29 command="find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
30 -o -print 2> /dev/null | sed 1d | cut -b3- | fzf +m --reverse --header='Jump to filemap <C-f> fzf_select'"
31 fzf = self.fm.execute_command(command, universal_newlines=True, stdout=subprocess.PIPE)
32 stdout, stderr = fzf.communicate()
33 if fzf.returncode == 0:
34 fzf_file = os.path.abspath(stdout.rstrip('\n'))
35 if os.path.isdir(fzf_file):
36 self.fm.cd(fzf_file)
37 else:
38 self.fm.select_file(fzf_file)