why non-text files' default opener is editor? #36

Closed
adam8157 opened this Issue Apr 20, 2012 · 6 comments

Comments

Projects
None yet
2 participants

Hi, hut

Why non-text files' default opener is editor now? It invoked open_with before.

I think the old way is better. We can't describe all types in rifle.conf, so many types are defined as unknown non-text types, it's not appropriate to open them all with editor.

I am so addicted to vim and ranger. I pressed "l, l, l", and bang! I opened a 2GB binary data file with vim by accident...

Owner

hut commented Apr 26, 2012

You can stop loading a large file in vim by pressing ^C. :)
Also, I changed the file opening system and the old behaviour, to open a console with "open_with" is not supported anymore, at least I don't see a way to easily implement it and still keep things as simple as they are.
But I could change the default program for unknown non-text types to "hexedit" which starts up instantly even on a 2GB file if that helps.

Not really agree with you.

How about just uncomment the last section of rifle.conf: "Define the editor for non-text files + pager as last action"?

Then ranger will warn "No action found" if files' type not described, and users could press r by themself.

Sorry, typo, I mean comment or remove the last section

Owner

hut commented Apr 27, 2012

Then you can't use E anymore to open the file in an editor

oops, forget that. the final patch is below(patched on master, 38c23f6)

---
 ranger/defaults/rifle.conf |    1 +
 ranger/ext/rifle.py        |    3 +++
 2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/ranger/defaults/rifle.conf b/ranger/defaults/rifle.conf
index 15a00da..bac98ff 100644
--- a/ranger/defaults/rifle.conf
+++ b/ranger/defaults/rifle.conf
@@ -174,5 +174,6 @@ label wallpaper, number 13, mime ^image, X = feh --bg-center "$1"
 label wallpaper, number 14, mime ^image, X = feh --bg-fill "$1"

 # Define the editor for non-text files + pager as last action
+label null, !mime ^text, !ext xml|csv|tex = null -- "$@"
 label editor, !mime ^text, !ext xml|csv|tex  = "$EDITOR" -- "$@"
 label pager,  !mime ^text  !ext xml|csv|tex  = "$PAGER" -- "$@"
diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py
index aef6c54..349c191 100755
--- a/ranger/ext/rifle.py
+++ b/ranger/ext/rifle.py
@@ -285,6 +285,9 @@ class Rifle(object):

        # Determine command
        for count, cmd, lbl, flgs in self.list_commands(files, mimetype):
+           if not label and count == 0 and lbl == "null":
+               self.hook_logger("Not defined type, E to open it with EDITOR, or r to invoke open_with")
+               return
            if label and label == lbl or not label and count == number:
                cmd = self.hook_command_preprocessing(cmd)
                command = self._build_command(files, cmd, flags + flgs)
-- 
Owner

hut commented Aug 6, 2012

I finally implemented this, similarly to your patch. If the command is "ask", then ranger will ask you for a command whereas rifle will simply say "unknown filetype!"
Unknown non-text files now have the command "ask" by default.

@hut hut closed this Aug 6, 2012

mullikine pushed a commit to mullikine/ranger that referenced this issue Nov 19, 2014

ext.rifle: implemented asking on unknown filetype (in ranger only)
this was requested here: ranger/ranger#36

adam8157:
  Why non-text files' default opener is editor now? It invoked open_with
  before.

  I think the old way is better. We can't describe all types in
  rifle.conf, so many types are defined as unknown non-text types, it's
  not appropriate to open them all with editor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment