2020-11-23 16:04:03 +01:00
|
|
|
from ranger.api.commands import Command
|
|
|
|
|
2021-04-17 14:52:37 +02:00
|
|
|
|
2020-11-23 16:04:03 +01:00
|
|
|
class paste_as_root(Command):
|
2021-04-17 14:52:37 +02:00
|
|
|
def execute(self):
|
|
|
|
if self.fm.do_cut:
|
|
|
|
self.fm.execute_console("shell sudo mv %c .")
|
|
|
|
else:
|
|
|
|
self.fm.execute_console("shell sudo cp -r %c .")
|
|
|
|
|
2020-11-23 16:04:03 +01:00
|
|
|
|
|
|
|
class fzf_select(Command):
|
|
|
|
"""
|
|
|
|
:fzf_select
|
|
|
|
|
|
|
|
Find a file using fzf.
|
|
|
|
|
|
|
|
With a prefix argument select only directories.
|
|
|
|
|
|
|
|
See: https://github.com/junegunn/fzf
|
|
|
|
"""
|
2021-04-17 14:52:37 +02:00
|
|
|
|
2020-11-23 16:04:03 +01:00
|
|
|
def execute(self):
|
|
|
|
import subprocess
|
|
|
|
import os.path
|
2021-04-17 14:52:37 +02:00
|
|
|
|
2020-11-23 16:04:03 +01:00
|
|
|
if self.quantifier:
|
|
|
|
# match only directories
|
2021-04-17 14:52:37 +02:00
|
|
|
command = "find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
|
2020-11-23 16:04:03 +01:00
|
|
|
-o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf +m --reverse --header='Jump to file'"
|
|
|
|
else:
|
|
|
|
# match files and directories
|
2021-04-17 14:52:37 +02:00
|
|
|
command = "find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
|
2020-11-23 16:04:03 +01:00
|
|
|
-o -print 2> /dev/null | sed 1d | cut -b3- | fzf +m --reverse --header='Jump to filemap <C-f> fzf_select'"
|
2021-04-17 14:52:37 +02:00
|
|
|
fzf = self.fm.execute_command(
|
|
|
|
command, universal_newlines=True, stdout=subprocess.PIPE
|
|
|
|
)
|
2020-11-23 16:04:03 +01:00
|
|
|
stdout, stderr = fzf.communicate()
|
|
|
|
if fzf.returncode == 0:
|
2021-04-17 14:52:37 +02:00
|
|
|
fzf_file = os.path.abspath(stdout.rstrip("\n"))
|
2020-11-23 16:04:03 +01:00
|
|
|
if os.path.isdir(fzf_file):
|
|
|
|
self.fm.cd(fzf_file)
|
|
|
|
else:
|
2021-04-17 14:52:37 +02:00
|
|
|
self.fm.select_file(fzf_file)
|