Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension-less files not supported? #23

Closed
kaushalmodi opened this issue May 12, 2017 · 11 comments
Closed

Extension-less files not supported? #23

kaushalmodi opened this issue May 12, 2017 · 11 comments

Comments

@kaushalmodi
Copy link

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.
@jarun
Copy link
Owner

jarun commented May 12, 2017

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.

@kaushalmodi
Copy link
Author

kaushalmodi commented May 12, 2017

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.

@jarun
Copy link
Owner

jarun commented May 12, 2017

What's the output of file -b CHANGELOG?

@kaushalmodi
Copy link
Author

kaushalmodi commented May 12, 2017

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?

@kaushalmodi
Copy link
Author

kaushalmodi commented May 12, 2017

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);

@kaushalmodi
Copy link
Author

Also I found the use of PAGER there more intuitive than EDITOR ( kaushalmodi@05d7641 ). If I wanted to edit the file, I would have hit the e binding.

@jarun
Copy link
Owner

jarun commented May 12, 2017

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.

@olethanh
Copy link

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”.

@jarun
Copy link
Owner

jarun commented May 13, 2017

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

@jarun jarun closed this as completed in cbbe032 May 13, 2017
@jarun
Copy link
Owner

jarun commented May 13, 2017

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

kaushalmodi pushed a commit to kaushalmodi/nnn that referenced this issue May 13, 2017
Merge fix for jarun#23
from upstream

jarun@cbbe032
@kaushalmodi
Copy link
Author

Thanks! I confirm this fix.

@lock lock bot locked and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants