mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 22:59:15 +00:00
ranger: fzf integration
This commit is contained in:
parent
4f0bd9c9e9
commit
645403156c
3 changed files with 45 additions and 4 deletions
32
nix/homeModules/common/ranger/commands.py
Normal file
32
nix/homeModules/common/ranger/commands.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# source: https://github.com/gotbletu/shownotes/blob/master/ranger_file_locate_fzf.md
|
||||
|
||||
from ranger.api.commands import Command
|
||||
import os
|
||||
|
||||
|
||||
class fzf_select(Command):
|
||||
"""
|
||||
:fzf_select
|
||||
|
||||
Find a file using fzf.
|
||||
|
||||
With a prefix argument select only directories.
|
||||
|
||||
See: https://github.com/junegunn/fzf
|
||||
"""
|
||||
def execute(self):
|
||||
import subprocess
|
||||
if self.quantifier:
|
||||
# match only directories
|
||||
command="fd . ~/Documents --type d | fzf"
|
||||
else:
|
||||
# match files and directories
|
||||
command="fd . ~/Documents | fzf"
|
||||
fzf = self.fm.execute_command(command, stdout=subprocess.PIPE)
|
||||
stdout, stderr = fzf.communicate()
|
||||
if fzf.returncode == 0:
|
||||
fzf_file = os.path.abspath(stdout.decode('utf-8').rstrip('\n'))
|
||||
if os.path.isdir(fzf_file):
|
||||
self.fm.cd(fzf_file)
|
||||
else:
|
||||
self.fm.select_file(fzf_file)
|
||||
Loading…
Add table
Add a link
Reference in a new issue