gotbletu / shownotes

notes for videos from my youtube channel
https://www.youtube.com/user/gotbletu
GNU General Public License v3.0
909 stars 174 forks source link

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

Open yyy33 opened 4 years ago

yyy33 commented 4 years ago
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)
lasers commented 4 years ago

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
yyy33 commented 4 years ago

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 commented 4 years ago

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