SourceTree: Adding a custom action to open a file in an external editor

Viewed 5038

SourceTree has a window called unstaged files where it shows files whose changes have not been committed. I want to right click on the file name & open it in an external editor. So I added a custom action -> Edit -> pathtoeditor\editor.exe $REPO\$FILE.

This launches the editor. But SourceTree also keeps showing a progress bar. progress bar The progress bar closes only after I close the external editor.

How do I avoid this? After opening the file in the external editor, I want SourceTree's UI to return to its normal state without waiting for the editor to exit.

3 Answers

This is an old question, but if someone else is looking for the answer currently the easiest way to accomplish this is to follow these steps

  1. Within SourceTree go to Tools -> Options
  2. Click Custom Actions
  3. Click Add
  4. Add the Caption
  5. For script to run, hit the three dot button and locate the .exe of the application you are wanting to open the file in
  6. Add the needed parameters to the parameters text box (in my case this is $FILE
  7. Click OK
  8. Restart SourceTree

New custom action window

Now if you right click on a file in Sourcetree and go to the custom actions menu it will now have the action you created. Click on it and it will open in the application you selected without keeping the progress bar open for no reason.

The issue is that SourceTree is waiting for the launched process to finish (which could be useful - for example when launching a merge tool, or some other task that requires action from SourceTree when it completes).

To launch a truly independent instance of your editor, use

cmd

as the "Script to run" and

/C start "" path_to_editor <parameters> "$REPO/$FILE"

as the parameter.

The /C option on cmd causes the command window to close as soon as it executes the start command, and the empty first parameter to the "start" is a dummy value for the command window that will never open. If path_to_editor contains spaces, then you have to enclose it in quotations.

Related