nnn icon indicating copy to clipboard operation
nnn copied to clipboard

nnn doesn't obey NNN_USE_EDITOR

Open serverhiccups opened this issue 8 years ago • 23 comments

Hi everyone, I'm sort of new to contributing to projects like these so sorry if I missed something, but, I'm having some problems with getting my files to open in the correct editor.

My problem is that even when NNN_USE_EDITOR is set to 1 (I tried set -Ux NNN_USE_EDITOR 1 in fish and export NNN_USE_EDITOR=1 in bash) some files still use open. Specifically .cpp, .md and other files have no problem opening in $EDITOR (vim) but when trying to open a .js file it opens in Sublime Text (My default GUI editor). I tried using the file command to investigate but both .md and .js files return the same thing. (index.js: text/plain; charset=us-ascii).

Any help with this would be appreciated.

OS: macOS 10.14 Shell: fish nnn version: 2.0 installed from homebrew

serverhiccups avatar Nov 27 '18 23:11 serverhiccups

What is the output of file -bi filename.js?

jarun avatar Nov 27 '18 23:11 jarun

I have added js to the mix.

jarun avatar Nov 27 '18 23:11 jarun

Looking at commit 0a8970a, it seems that you just added it so a list of file types. Maybe a more future proof option could be allowing the user to define what extensions should count as text.

serverhiccups avatar Nov 28 '18 00:11 serverhiccups

I left a question before the commit. What do you see?

The logic is here: https://github.com/jarun/nnn/blob/v2.1/src/nnn.c#L2607-L2626

We don't want to add a config file for what's detected properly in most cases. What would you do differently?

jarun avatar Nov 28 '18 00:11 jarun

You redacted this:

I'm not sure if this is still useful but the output is regular file.

That's why it's not detected correctly. What is the output of file -bi for md and cpp?

jarun avatar Nov 28 '18 00:11 jarun

Sorry, I redacted it because I didn't think that it would be very useful. The output for both .cpp and .md files is still regular file. Re: config file, I'm not sure, I guess you're right as it would be duplicating functionality already in file.

serverhiccups avatar Nov 28 '18 01:11 serverhiccups

Can you check if omitting -b helps?

jarun avatar Nov 28 '18 02:11 jarun

I am trying to figure out how you got:

I tried using the file command to investigate but both .md and .js files return the same thing. (index.js: text/plain; charset=us-ascii).

jarun avatar Nov 28 '18 02:11 jarun

Did you try just file index.js?

jarun avatar Nov 28 '18 02:11 jarun

I used file -I to get the MIME type.

serverhiccups avatar Nov 28 '18 03:11 serverhiccups

Great! Does file -bI filename show the mime as text/.... Please tech with different file types to confirm this.

If it does, I will pass different args for Linux and OS X and it would be the correct fix.

jarun avatar Nov 28 '18 03:11 jarun

I have made the change to pass -I at 8aa72a40a3021508888441b60dd6f324eefe76ee. Thanks for providing all the info.

Please test it out!

jarun avatar Nov 28 '18 03:11 jarun

Removed JS from mime list at d8df13f665b035cad0cceee48f388f4a9b03b9f2.

jarun avatar Nov 28 '18 03:11 jarun

I just built and tested it and it works great! Thanks for taking the time to fix this.

serverhiccups avatar Nov 28 '18 04:11 serverhiccups

No problem! Have fun!

BTW, I don't own a Mac and occasionally I need someone to help me out with insights for any issue reported on Mac.

Would you be interested in joining the project as a collaborator?

jarun avatar Nov 28 '18 04:11 jarun

Hello! I believe I'm having the same issue in linux with application/json; charset=us-ascii type files, with or without the .json extension.

I'm using nnn-git from the arch user repository.

dv-blk avatar Jan 31 '19 08:01 dv-blk

What is the output of file json_file?

jarun avatar Jan 31 '19 08:01 jarun

package.json: JSON data

dv-blk avatar Jan 31 '19 08:01 dv-blk

Sorry, if on Mac, try: file -bI json_file, else file -bi json_file.

If it still shows the same, the program is behaving correctly. We look for the pattern text/. E.g.:

text/x-c; charset=utf-8

jarun avatar Jan 31 '19 08:01 jarun

Thanks, I'm actually on linux. Here's the output of those commands.

file -bI package.json

file: invalid option -- 'I'
Usage: file [-bcCdEhikLlNnprsvzZ0] [--apple] [--extension] [--mime-encoding]
            [--mime-type] [-e <testname>] [-F <separator>]  [-f <namefile>]
            [-m <magicfiles>] [-P <parameter=value>] <file> ...
       file -C [-m <magicfiles>]
       file [--help]

file -bi package.json

application/json; charset=us-ascii

file -v

file-5.35
magic file from /usr/share/file/misc/magic

dv-blk avatar Jan 31 '19 09:01 dv-blk