There's an external command I'm using constantly - basically launching a batch file. I'd like to put a toolbar button (and possibly keyboard shortcut) for this into the IDE. Is there an easy way to do that?
First, add an item to your Tools menu by choosing Tools, External Tools, and filling out the dialog, like this:
Then bring up Tools Customize, click the Keyboard button at the bottom, and find the appropriate external tool number:
All the configured external commands in VS are available to add to a Toolbar or Menu through the Tools>Customize menu as "External Command ##". You just need to know which number corresponds to the particular command you've configured. I believe it is in order of entry in the external commands list.
Similarly, you can find those names in the commands list in Options>Environment>Keyboard and assign a shortcut to your command that way.
Related
In Intellij IDE's such as PyCharm or Idea there is an option to customize the menu and toolbar by right-clicking the toolbar and picking Customize menus and toolbars. While it is possible to select almost any IDE action there doesn't seem to be a way to add a button that runs a custom shell script. The only way to run a shell script seems to be by adding a Run Configuration of type Shell Script and then invoking it via the Run button, but is there a way to have multiple clickable buttons on the toolbar that would run arbitrary shell commands? (no need for an actual console)
In Jetbrains jargon this is called an external tool and is configured under Preferences -> Tools -> External Tools.
Once you added the commands you need as external tools you can add them as toolbar buttons by right-clicking the toolbar and picking Customize menus and toolbars, expand the node under the Main Toolbar, click ➕ to add an item and then type external in the search box to select your "external tools" and optionally set custom icons for them.
I find I go to the My Work pane inside the Team Explorer frequently, but I haven't found a way to get there in one click. I can create a shortcut key for the command TeamFoundationContextMenus.Commands.GoToMyWork and that works, but I'm looking for something I can click on a toolbar.
So specifically, my question is: where in the toolbar customization "Add Command" list does this option exist? There are several categories and many items in each, and I haven't found a way to search, only scroll.
More generally, and if the option doesn't exist, is there a way to use the command name in the keyboard shortcut customization to create a toolbar button for that command?
For a toolbar you can add commands only from the existing VS menu.
For additional commands, you can create an intermediate Visual Commander command DTE.ExecuteCommand("TeamFoundationContextMenus.Commands.GoToMyWork") and then add this VCmd.Command01 command to a toolbar.
How would one go about setting up some hotkeys for commonly used SVN actions such as diff?
Currently to view diff, I have to select file(s), then right click, navigate to TortoiseSVN and then select Diff action. Quite a few steps for something used often.
Instead, I would like to select file and use hotkey(for example Ctrl-Alt-F) to do the same Diff action.
Searching for solutions, I have found some people running AutoHotKey scripts to do similar things, but it seems like an overkill.
I made a hotkey shortcut(using standard Win 7 method of creating a shortcut then adjusting its properties) to run TortoiseMerge, which is the tool that displays the diff, but such a shortcut ignores current file selection and brings up a blank TortoiseMerge.
Any ideas to try?
You can modify the TortoiseSVN context menu and place your favorite commands at the root of the context menu. This way you have only to click twice for a diff. Not that much, I think.
Another option would be to use an advanced file manager (like Total Commander or FreeCommander) which enables you to define custom menu commands with custom hot keys.
In Total Commander this would be "Change Start Menu":
Command: C:\Program Files (x86)\TortoiseSVN\bin\TortoiseProc.exe
Parameters: /command:diff /path:%P\%N
Shortcut Key: CRTL+ALT+F1
Whether shell context menu or hotkey, you need at least 2 steps to run a TortoiseSVN command:
Select the file (selecting and right clicking to open the context menu is a single action)
Run the command (click on the context menu item or press the shortcut key)
From this point of view it's just a question of your personal preference: should I click twice or should I click once and leave the mouse for pressing a key? ;-)
Autohotkey is overkill for a single key, but you can collect the hotkeys for actions you might perform in any window type all in a single script. As a result, you can have hotkeys perform fairly complex actions in one class of windows, and the same hotkeys perform different actions in another window type using the '#IfWinActive' directive.
For example, this URL mentions adding hotkeys for commit and update; you could add a key for your diff need, and perhaps one for log or some other svn option you perform frequently.
For some reason, bringing up the explorer context menu is slow for me in Windows 7. Adding these hotkeys really improved my workflow.
Note: you can also prefix that URL's example code with the following:
GroupAdd explorers, ahk_class ExploreWClass
GroupAdd explorers, ahk_class CabinetWClass
#IfWinActive ahk_group explorers
And suffix it with:
#IfWinActive
And those specific hotkeys will execute the TortoiseSVN-specific commands when Windows Explorer has focus, and be passed through in all other cases.
You could try directly calling the process with the correct parameters instead of worrying about right-click context menus.
For example, I was able to set up a shortcut directly to the following item:
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:update /path:"c:\Source"
From there, you can call this shortcut from your hotkey program, or if you prefer a out-of-the-box solution, map a folder directly to the task bar (I labeled mine "o" for aesthetics) and stick that shortcut in this folder.
Theoretically, you could have one shortcut per operation, per repository.
Looking at the problem more generally, I'd say that this is a workflow issue. Presumably the reason you want to find a quicker way of finding diffs is because you want to do it for a number of files. In that case, go to the root of your working copy and choose TortoiseSVN -> Check for modifications. That will show you a list of changed files. Do get the diffs, just double click on each.
Install the StExBar, then add commands for diff/update/commit/... and specify the corresponding TortoiseProc.exe command.
And of course assign a hotkey for the command.
You can use context menu shortcuts.
Just open code folder in explorer and use below:
Commit: alt + F + C
update: alt + F + U
Check for updates: alt + F + T + F
So you can press above keyboard shortcuts to commit instead of having to right click directory then click commit.
What I would like
I would like to easily run a batch file without leaving Visual Studio. The batch files are not always the same, they change depending on the solution I'm working with.
What I know so far
I know you can create custom shortcuts in the Tools section of Visual Studio (Under External Tools).
My solutions have various scripts/batch files and I wish there was a way to create shortcuts under a solution folder or some other place that is solution specific.
I can create the scripts but there doesn't seem to be a way to run the script. I don't like having to open Windows Explorer each time I want to run a script.
Perhaps an add-in that would start a process with the selected file in the solution explorer? Or something similar?
Here is a full steps on how to add the external tool to run the batch files by right click on the file and select "Run the batch file", also whenever you need to edit the file, just open and edit it.
Here's how to do it...
Create an external tool called "Run batch file"
1) From Tools-> External Tools, create a new and put the below parameters:
2) Set the Command to: CMD.EXE
3) Set the Arguments to: /c "$(ItemPath)"
4) Set the Initial directory to: $(ItemDir)
5) ![DO NOT Check the "use output window" check box and then Apply to create the command
Note where the new command appeared in the list of commands.
The external commands are numbered from 1 starting below the divider bar.
#1 is usually "Create GUID"
To make it easy to remember you can move the new command to the top, to be the number one command in the list.][1]
6) Now go to Tools -> Customize and select the commands tab.
7) Select the Context menu radio button and select "Project and Solution Context menus | Item" from the drop down.
8) Now use "Add Command..." to add a new command
9) In the Categories list select "Tools"
10) From the commands select the "External Command #" that corresponds to the position of the "Run Batch file" custom command you noted the number of in step 5 above.
11) Move it to the right position in the list add keyboard short cuts etc.
12) Close the dialogue.
Now right click on the batch file and you should see a "Run batch file" menu item. This will execute th batch file and show it's output in the VS Output window.
Hope it helps.
I did this by right clicking the batch file and choosing "Open With", then I added a new editor and used explorer.exe (and then set that to be the default editor).
The best way to proceed is to write an external tool, and then you can pass in parameters based on your current solution that is loaded.
There are many project and solution specific variables you can pass to your external tool.
Open up the 'External Tools' dialog, and select your tool in the list box.
You will see the title of your external tool, as well as the command that points to the script or batch script you want to call.
The arguments edit box has a button next to it with an arrow next to it. Click the arrow and you will see a big list of variables, or parameters, you can pass to your external tool.
So, for instance you can use the following:
$(ProjectDir) - The full path directory of the project you are working on.
for instance "C:\builds\myproject"
$(ProjectPath) - The full path name of the vcproj you are working on.
for instance "C:\builds\myproject\foo.vcproj"
$(ProjectName) - The name of the project.
for instance "foo"
$(SolutionDir) - The full path directory of the solution that is currently loaded.
for instance "C:\builds\mysolution"
etc...
Will the Build Event hooks (pre-build, pre-link, post-build) be of any use to you? Also you can check out the Custom build setup too. Those are part of the solution.
You can add a new Makefile project to your solution. A Makefile project is a simple Visual Studio project whose build action is any command line you want. It is listed under the Visual C++ - General category in the new project dialog. In your case, just set the build command to invoke your batch script. Then, to execute your script while working in your solution, just right click on the Makefile project in the Solution Explorer and choose the Build context menu item.
Since you intend to run this script run on-demand (as opposed to running each time you build) you will want to remove it from the build in the Configuration Manager. Don't forget to disable building the project for all platforms and configurations.
Most of the macros are available to the Makefile project's build command line, although perhaps some that are associated with your main project will not have the correct value.
On my environment (Visual Studio 2022 v17.3.6 on Windows 11 v21H2) the $(ItemPath) parameter for cmd.exe leads to an error, but it works properly without:
This seems reasonable to me as the command is called "Open With" and works like the Windows "Open With" command by autmatically passing the file as an argument.
Is it possible to run a batch file as a menu item in studio 2008?
Yes, go to Tools | External Tools in the menus and add your batch file as the Command. You can also pass in any arguments that you want such as the build target, project directories, etc.
Once you do this, your batch file will appear as one of the items on your tools menu. If you want, you can then add a toolbar button for it by going Tools | Customize | Tools and dragging the External Command # that matches your tool to the toolbar. You will then want to change it to an icon and select an image for it.
The tools are numbered 1 based in the order they appear in the menu.
Run batch files in VS Solution Explorer directly
This is much better than having external tool since you can execute a batch file simply by double clicking on it in solution explorer just as if you were opening a code file. I've written a blog post about it that will help you lots to configure it and of course use it.
A sidenote
You've asked this question 2 years ago, but I see that nobody mentioned this technique so I'm providing this answer for any future reference. I hope it gets upvoted, so it will be near the top for readers to see.
Use "Tools"/"External Tools..." menu item and add your bat-file to "Tools" menu
As A refinement to the given answer:
Say your project/solution have several BAT that are project specific - you wouldn't want to run one from another project - that's what could happen with the above answer - because you have hard wired the path to the bat.
Just set up one external tool nameed "Run BAT", sets its Command to $(ItemPath), and set the initial directory to $(ItemDirectory), The dialog will whinge that this is not a real executable - but ignore that.
Tie the tool to a button if you want.
Now to run the BAT of choice from the project or solution - just open the .bat for editing and select the "Run BAT" external tool.
you could also set the "use output" option as well and the bats output will be in the output window.