I would like to open a file from Cygwin into Windows' configured text viewer, even if that file type is not associated with the text viewer already (i.e. Windows doesn't consider it a text file).
For my specific case, I use Notepad++ for general text file viewing and code editing, and I have it associated with most non-executable plain text file extensions (.txt, .log, etc) but not with executable ones (.pl, .py, etc). I now want to be able to open a Perl file into it from a Cygwin bash prompt.
I know I can use cygstart to open a file with the Windows application associated with that file type. So e.g. cygstart Readme.txt
will open in the Notepad++ for me based on the .txt extension. However, if I cygstart prog.pl
, it tries to run it with Windows' default Perl interpreter because of the .pl extension.
I also tried cygstart -e prog.pl
, but that opens in Window's default text Editor, Notepad.
So, is there a way to have Cygwin open a plain text file in Windows' configured text viewer even if the extension is not already associated with the said viewer?
Note: I'm testing this out manually in a Bash prompt, but I want to roll this into a shared script that can then open Perl files for the user to edit. Hence my concerns below around making it portable to other users. For the same reason, I'm not interested in "just use Vim!" solutions.
Some thoughts I had so far:
- Associate all the file types I want to be able to open like this with the same viewer, i.e. Notepad++ in my case. The downside is it requires an update to the Windows file associations every time you want to open a new file type, and requires any other users to do the same thing.
- Change the Windows default Text editor, i.e. the app it uses when you right-click ->Edit in an explorer window. I don't know if this can be done and it's not a terrible option if it can be done. I.e. I can communicate this to another user as a one-time config step.
- Hard code the desired viewer path as an alias an use that instead. E.g. right now I have in my aliases
alias npp='"C:/Program Files (x86)/Notepad++/notepad++.exe"'
and I can do what I want withnpp prog.pl
. This presupposes that everyone who is going to use this method has the same editor installed or knows how to set up aliases. - Get the path to the configured Windows text file viewer (maybe from cygstart?) and then open another non-associated file type using that path.
.txt
. Practicals are unfortunately beyond me as I have currently no Win installation. And thanks for reminding me of the exact command :-D – Peregrino69 Mar 06 '23 at 13:08