Nnn: Extension-less files not supported?

Created on 12 May 2017  ·  11Comments  ·  Source: jarun/nnn

When I hit Return on files like CHANGELOG or Makefile, I get "No file association".

  • Should such files be attempted to be opened as plain text?
  • Or may be a check should be made if a file is plain text (something like this?)

    • I don't know how that would be done in a C code, but something like that should be available.

All 11 comments

Are you on v1.1 (released today)?

Which opener variable did you define? We do detect and attempt to open plaintext files in EDITOR (fallback vi). But that works only if NNN_OPENER is not used. I don't have NNN_OPENER and it's working for me right now.

I have none of the NNN_* env vars defined. I get the same behavior on the v1.1 release too.

> echo $NNN_OPENER
NNN_OPENER: Undefined variable.
> echo $EDITOR
emacsclient

If it matters, I am using tcsh shell. I can easily get that "No association" message by launching nnn in this repo root, navigating to the CHANGELOG file and hitting RET.


To add, if I hit e instead of RET on CHANGELOG, the file opens fine in my default $EDITOR.

What's the output of file -b CHANGELOG?

What's the output of file -b CHANGELOG?

That's it! It outputs ASCII English text, not ASCII text. May be you should match for a regular expression like ASCII .*text?

This is not a good fix, but I tested this out and it works for me:

diff --git a/nnn.c b/nnn.c
index 110495e..e6b8d2b 100644
--- a/nnn.c
+++ b/nnn.c
@@ -1598,7 +1598,7 @@ nochange:
                if (get_output(cmd, MAX_CMD_LEN) == NULL)
                    continue;

-               if (strstr(cmd, "ASCII text") != NULL) {
+               if (strstr(cmd, "ASCII English text") != NULL) {
                    exitcurses();
                    run = xgetenv("EDITOR", "emacsclient");
                    spawn(run, newpath, NULL, 0);

Also I found the use of PAGER there more intuitive than EDITOR ( https://github.com/kaushalmodi/nnn/commit/05d76410ff26558ccd0eec92e31c0c16ca562c5b ). If I wanted to edit the file, I would have hit the e binding.

I would have to look into the magic numbers and see if I can do anything better than this.

If I wanted to edit the file, I would have hit the e binding

I don't think this is too relevant here. The keybind here is Enter and I don't see a reason to open a text file in read-only mode by default.

You can use the "-i or --mime" option of file which return the mime type, which should be easier to parse and not depends on locales

 -i, --mime
         Causes the file command to output mime type strings rather than the more traditional human readable ones.  Thus it may say ‘text/plain; charset=us-ascii’ rather than “ASCII text”.

@olethanh yes, that'ld be nice! I'll push it in.

@kaushalmodi @olethanh please test with the fix and confirm everything works as expected. Thanks!

Thanks! I confirm this fix.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amanjitsk picture amanjitsk  ·  7Comments

harriott picture harriott  ·  6Comments

snide picture snide  ·  6Comments

kuntau picture kuntau  ·  3Comments

akimdi picture akimdi  ·  6Comments