shownotes icon indicating copy to clipboard operation
shownotes copied to clipboard

Hello,I don't know python, can you help me to modify this code to open directly if it is a file

Open yyy33 opened this issue 5 years ago • 3 comments

import os
from ranger.api.commands import Command
# fzf_fasd - Fasd + Fzf + Ranger (Interactive Style)
class fzf_fasd(Command):
    """
    :fzf_fasd

    Jump to a file or folder using Fasd and fzf

    URL: https://github.com/clvv/fasd
    URL: https://github.com/junegunn/fzf
    """
    def execute(self):
        import subprocess
        if self.quantifier:
            command="fasd | fzf -e -i --tac --no-sort | awk '{ print substr($0, index($0,$2)) }'"
        else:
            command="fasd | fzf -e -i --tac --no-sort | awk '{ print substr($0, index($0,$2)) }'"
        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)

            if os.path.isdir(fzf_file):
                self.fm.cd(fzf_file)
            else:
                self.fm.select_file(fzf_file)

yyy33 avatar May 11 '20 12:05 yyy33

I think you're looking for something like this.

diff --git a/ranger_fasd_fzf.md b/ranger_fasd_fzf.md
index 770de8e..4da946c 100644
--- a/ranger_fasd_fzf.md
+++ b/ranger_fasd_fzf.md
@@ -47,6 +47,7 @@ https://www.youtube.com/watch?v=ur81Y-mV5Us
                     self.fm.cd(fzf_file)
                 else:
                     self.fm.select_file(fzf_file)
+                    self.fm.execute_console("open_with")
     
     # Fasd with ranger (Command Line Style)
     # https://github.com/ranger/ranger/wiki/Commands

lasers avatar May 12 '20 19:05 lasers

I think you're looking for something like this.

diff --git a/ranger_fasd_fzf.md b/ranger_fasd_fzf.md
index 770de8e..4da946c 100644
--- a/ranger_fasd_fzf.md
+++ b/ranger_fasd_fzf.md
@@ -47,6 +47,7 @@ https://www.youtube.com/watch?v=ur81Y-mV5Us
                     self.fm.cd(fzf_file)
                 else:
                     self.fm.select_file(fzf_file)
+                    self.fm.execute_console("open_with")
     
     # Fasd with ranger (Command Line Style)
     # https://github.com/ranger/ranger/wiki/Commands

Unfortunately, it does not work properly, I received this prompt

xdg-open: unexpected option '--'
Try 'xdg-open --help' for more information.

yyy33 avatar May 14 '20 09:05 yyy33

I think you're looking for something like this.

diff --git a/ranger_fasd_fzf.md b/ranger_fasd_fzf.md
index 770de8e..4da946c 100644
--- a/ranger_fasd_fzf.md
+++ b/ranger_fasd_fzf.md
@@ -47,6 +47,7 @@ https://www.youtube.com/watch?v=ur81Y-mV5Us
                     self.fm.cd(fzf_file)
                 else:
                     self.fm.select_file(fzf_file)
+                    self.fm.execute_console("open_with")
     
     # Fasd with ranger (Command Line Style)
     # https://github.com/ranger/ranger/wiki/Commands

Is there a way to call rifle directly instead of xdg-open

yyy33 avatar May 14 '20 09:05 yyy33