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

[CLOSED] Fix for launching Brackets from command line (Win Only) #340

Open
core-ai-bot opened this issue Aug 17, 2021 · 23 comments
Open

[CLOSED] Fix for launching Brackets from command line (Win Only) #340

core-ai-bot opened this issue Aug 17, 2021 · 23 comments

Comments

@core-ai-bot
Copy link
Member

Issue by nethip
Wednesday Apr 01, 2015 at 12:54 GMT
Originally opened as adobe#510


The change basically fixes the following problems.

  1. Our command line arguments were never respected as Brackets was expecting a full path and we were just passing the file names

  2. Adding the install location to the PATH variable which will allow users to launch Brackets just by typing "Brackets" instead of full path like "C:\Program Files (86)\Brackets\Brackets.exe".

This is a Win only change.


nethip included the following code: https://github.com/adobe/brackets-shell/pull/510/commits

@core-ai-bot
Copy link
Member Author

Comment by nethip
Wednesday Apr 01, 2015 at 12:56 GMT


@JeffryBooher @ingorichter Please review with when you guys get some time.

@core-ai-bot
Copy link
Member Author

Comment by nethip
Thursday Apr 02, 2015 at 10:45 GMT


Adding @RaymondLim @redmunds

@core-ai-bot
Copy link
Member Author

Comment by le717
Wednesday Apr 08, 2015 at 19:57 GMT


No no no no. I object to adding Brackets to the PATH. That is usually reserved for runtime utilities or interpreted programming languages (python, java, node) or critical items needed for system stability (PowerShell, GPU drivers, system32). I don't think we need to add Brackets to the PATH just to get command-line arguments working. I think it was @JeffryBooher who brought it up. There's another way to do it. Let me find it real quick.

@core-ai-bot
Copy link
Member Author

Comment by le717
Wednesday Apr 08, 2015 at 20:09 GMT


Found it. adobe/brackets#7482 (comment) (referenced section). I think that should work in the same manner as adding it to the PATH, but with less risk. FWIW, adding applications to the system PATH is generally frowned upon, and when the implementation is flawed the entire PATH can be wrecked (I've had this happen before). I highly advise a followup PR to replace the PATH editing with this registry entry (after confirming it works, which I am pretty sure it does) in this same release (1.3).

@core-ai-bot
Copy link
Member Author

Comment by nethip
Thursday Apr 09, 2015 at 01:55 GMT


@le717 Thanks for sharing the link. If we could do this with a registry entry we could very well do that easily. Let me go through the link and consider other alternatives.

@core-ai-bot
Copy link
Member Author

Comment by nethip
Thursday Apr 09, 2015 at 10:22 GMT


@le717 The registry entry only takes care of launching Brackets using _Run Command..._ not through command line. To be more technical, any tool that uses ShellExecuteEx() to launch a new process will be able to successfully find the target app with an entry in HKLM\SOFTWARE\Microsoft\Windows\AppPaths. But I doubt if cmd.exe or GitBash use ShellExecuteEx() to launch apps.

Once thing to note here is that we are relying on the MSI that is the standard windows installer that for sure understands how to manage the PATH update efficiently (I have tested this with variety of test cases and the installer does a good job of undoing whatever has been done through the installation process, during uninstallation). It would have been a bigger problem if we were updating the PATH variable programatically.

Another option is to create an alias to Brackets, in Windows/System32 folder, which is even more uglier than updating the PATH variable.

Considering the no of votes 81 for this trello card (https://trello.com/c/dRNqhd2L/349-s-open-file-folder-from-command-line-on-win-and-linux) I think we should support this feature.

@core-ai-bot
Copy link
Member Author

Comment by le717
Friday Apr 10, 2015 at 15:11 GMT


Considering the no of votes for this trello card I think we should support this feature.

I agree this feature should be added, but I don't agree this is how it should be added.

The registry entry only takes care of launching Brackets using Run Command... not through command line. To be more technical, any tool that uses ShellExecuteEx() to launch a new process will be able to successfully find the target app with an entry in HKLM\SOFTWARE\Microsoft\Windows\AppPaths. But I doubt if cmd.exe or GitBash use ShellExecuteEx() to launch apps.

The run command is a command prompt, but only runs one command rather than many. Also, did you compare the .bat script with the MSDN docs on registering an application? I think this method will work. I have Word installed and I can open it from the command-line, and it is not in my PATH nor is there a symlink in System32 (which agreed is ugly).

@core-ai-bot
Copy link
Member Author

Comment by nethip
Friday Apr 10, 2015 at 15:20 GMT


I am open towards making this change if this can be done through a registry entry. I could not find a way of to do this. In fact I would recommend this registry way. Can you share the details of .bat registration in the registry. It would surely help me in doing this change.

@core-ai-bot
Copy link
Member Author

Comment by le717
Friday Apr 10, 2015 at 15:21 GMT


OK, I apologize. I have always assumed the run command was a mini-command prompt. I just tested it now, and you are right, it only works for Run. I still think it is possible without the PATH...

@core-ai-bot
Copy link
Member Author

Comment by le717
Friday Apr 10, 2015 at 15:45 GMT


Just so I'm totally clear, adding this to the PATH permits what, again? Opening files/folders in Brackets using open with, or opening a command prompt and typing brackets "some/file/here.js"?

@core-ai-bot
Copy link
Member Author

Comment by nethip
Friday Apr 10, 2015 at 16:26 GMT


No worries. Let me know if you if you come across any interesting solitons to fix this.

To answer to your last question it does both. We have changed the installer to add open with menu to file and folder context menus. Also Brackets can be launched from command line with file/folder name as argument.

@core-ai-bot
Copy link
Member Author

Comment by le717
Friday Apr 10, 2015 at 19:34 GMT


I found this a while back. It uses the registry to open files from the context menus. https://gist.github.com/wormeyman/75e3036993136c8b1830

As for the command line, I know of 0 programs that add themselves to the PATH just to open files like that. As I said, it is kinda frowned upon to add a program to the PATH in general unless it is an absolute last resort to do something or it is a purely command line utility (git, python, java, etc). GUI programs like Brackets do not fit into those use cases. In fact, adding to the PATH works around functionality Windows already has. I found that after adding that app registration registry key, I could run start brackets "path\to\file.js" and start brackets "path\to\folder" and it worked. The start command is an underused and underexposed gem, and that is what should be used in this case, not adding Brackets (a GUI'd code IDE) to the PATH.

Maybe a forum topic should be raised asking about this issue. As I said, I know of zero IDEs that add themselves to the PATH, and it almost sounds to me this is a case of "The user doesn't quite know what they are asking". Also, the 81 votes were probably more towards the context menus than adding to the PATH.

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Friday Apr 10, 2015 at 22:23 GMT


@abose @nethip Let's discuss this a little more before committing to ship as-is -- given that this is optional or not even a feature in many (most?) other Windows editors

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Friday Apr 10, 2015 at 22:28 GMT


@le717 It's a popular feature in Mac code editors to be able to launch from the command line -- e.g. mate <filename> to launch TextMate. Presumably the use cases would be equally as common on Windows. And that kind of shorthand only works if an app is in the PATH. That said, in most other apps the user has to either manually modify their PATH, or there's a checkbox in the installer for opting in/out. That seems like the safer bet for Brackets too...

@core-ai-bot
Copy link
Member Author

Comment by ryanstewart
Friday Apr 10, 2015 at 22:52 GMT


Sorry for jumping in late. Just did a bit of research, and like @peterflynn I think there's some confusion/difference between the Windows and Mac experience. On Mac, as Peter says, this is a pretty common feature. TextMate and Sublime both enable it. I assumed Sublime behaved the same way on Windows, but it looks like that's not the case. Googling around it looks like you can do this with Sublime, but it's a very manual process.

I think most of the votes in the card referenced are from Mac users who want to be able to use Brackets they way they use TextMate or Sublime.

So the big question is whether or not we want to automatically do that for Windows users. I kind of think putting it in the debug menu is enough but maybe we need a more explicit warning. @le717 do you think this would be worth emailing out to the Brackets-Dev group about and getting feedback?

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Friday Apr 10, 2015 at 23:08 GMT


@ryanstewart Even on Mac it's not that clear cut -- I'm pretty sure TextMate requires you to manually modify your path or add an alias somewhere. Not sure if any editors other than Sublime automatically add themselves.

Re votes on the card: until this week I think the title/description was Mac-only, so that is probably a safe assumption about what the voters wanted :-)

@core-ai-bot
Copy link
Member Author

Comment by le717
Friday Apr 10, 2015 at 23:33 GMT


So the big question is whether or not we want to automatically do that for Windows users. I kind of think putting it in the debug menu is enough but maybe we need a more explicit warning. @le717 do you think this would be worth emailing out to the Brackets-Dev group about and getting feedback?

Yes, I do think this is worth getting feedback from Brackets-Dev.

@core-ai-bot
Copy link
Member Author

Comment by nethip
Saturday Apr 11, 2015 at 04:57 GMT


@peterflynn @ryanstewart I am not sure if only MAC users had gone and up voted this considering the fact that there are multiple mentions of this being supported on Windows.

We could do what Peter had suggested on Windows like providing a checkbox for users to opt out of this.

@core-ai-bot
Copy link
Member Author

Comment by MarcelGerber
Sunday Apr 12, 2015 at 16:13 GMT


I also think this shouldn't be the default behavior on Windows. As @le717 mentioned, usually only command-line only tools add themselves to the PATH; I've got Sublime Text 3 and Notepad++ installed over here and neither of them added themselves to PATH.
Also, currently, it could happen that Brackets node.exe (in the install directory) is called instead of the actual node.exe if Brackets' PATH entry comes before the other one. That would be very, very, very bad.

@core-ai-bot
Copy link
Member Author

Comment by nethip
Sunday Apr 12, 2015 at 16:29 GMT


@marcelgerber That's a very good catch. We are thinking of making this PATH change optional in the installer, through a check box. Now I am thinking should we even do that.

However, we are going to add one checkbox in the installer for adding "open with Brackets" menu to file and explorer menu.

@core-ai-bot
Copy link
Member Author

Comment by le717
Monday Apr 13, 2015 at 19:12 GMT


@marcelgerber brought up a very good point with node, and such a problem can happen very easily (just install Node and let the installer add it to the PATH, then use this PR to install Brackets. Tada!). As I've stated, adding Brackets to the PATH does not need to happen at all. If people want to load files from the command-line, registering Brackets and using start (as I stated in adobe#510 (comment)) will do.

However, we are going to add one checkbox in the installer for adding "open with Brackets" menu to file and explorer menu.

Yes, please do. That's been a long time complaint about the Windows installer (see the very long discussion and resulting Trello card at adobe/brackets#6073), and making this an (I might suggest default, but we'll see) option will help remedy those complaints.

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Monday Apr 13, 2015 at 22:59 GMT


@marcelgerber Very good catch! Too bad we haven't yet figured out how to rename the executable back to "Brackets-node.exe," since that would have mitigated the problem...

@nethip Seems like we could solve using a script for indirection, similar to what we do on Mac. E.g. add a "brackets.bat" to the build in its own directory (INSTALL_DIR\launcher\brackets.bat?), and then add that dir to the path instead of the root install dir.

@core-ai-bot
Copy link
Member Author

Comment by nethip
Tuesday Apr 14, 2015 at 14:04 GMT


@peterflynn @marcelgerber @le717 @ryanstewart

I have created a new PR for this adobe#514.

These are the changes in nutshell

  • Made the update path and context menu addition to file and folder context menus optional.
  • The PATH varible will now be [INSTALLDIR]/command.
  • Changed project setup scripts to create commands/brackets.bat by copying it from scripts/brackets.bat
  • Changed the Gruntfile to copy the new folder command to Brackets staging area.

So basically now we have a new folder called [INSTALLDIR]\command which contains the script brackets.bat. This is what is going to be added to the PATH so that anyone when type brackets from command line, it is going to invoke this script. Basically this script will contain this.

@echo off
start Brackets.exe $*

start command now will be able to find Brackets.exe as we now have a new entry in Registry which will make Brackets runnable from Run Command as well.

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersoon\App Paths\Brackets.exe

I have put in some placeholder string for the checkboxes inside the installer. Feel free to suggest strings for these.

  • Update PATH environment variable with Brackets install location ( in order to launch Brackets from Command Line)
  • Add "Open With Brackets" menu to file and folder context menus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant