Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

102 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is it?

#DevComrade is a free and open-source tool for Windows. It helps developers to copy, paste and run text.

Features

  • Press Ctrl+V to paste plain text into any Windows application. The text has no formatting. You can also use the other usual paste shortcuts, such as Shift+Ins or right click and Paste.

    DevComrade monitors the Windows Clipboard. When the clipboard contains text with formatting from HTML, RTF, PDF or Word, DevComrade replaces the text with plain text. You can then paste the plain text anywhere. DevComrade uses the Win32 Clipboard Monitoring API to do this. To start or stop this function, use the Win+F10 menu, or the .config file.

  • The built-in Clipboard Notepad:

    • Press Shift+Alt+Win+\ to edit the clipboard text in the built-in Notepad.
    • Press Control+Enter to close the Notepad and save the text to the clipboard.
    • Press Esc to close the Notepad and discard the text.
  • Press Win+\ to paste plain text as one line. DevComrade removes the line breaks. Use this to paste into a command line.

  • Press Win+Alt+\ to paste plain text with more than one line.

  • Press Win+Alt+N to paste only the digits. Use this for a credit card number or a bank account number.

  • Select Convert to <pre> in the menu to put a <pre> tag around the clipboard text. This command has no hotkey. Use it to paste code into a Microsoft Teams chat as HTML. (Frequently, no other method works.)

  • Press Win+F10 or Win+Alt+. to open the main menu. This is the same menu that you get when you click the system tray icon.

Purpose

Copy-pasting from the online docs, StackOverflow or numerous blogs can be a tedious and sometimes even a dangerous task. Does the following sound familiar: you paste some text from a web page into a Terminal command line, and it gets executed immediately, before you even have a chance to edit it? Only because there was a CR/LF character at the end of the clipboard text.

Or, have you ever been annoyed with some broken formatting, indentation, inconsistent tabs/spaces when you paste a piece of code into Visual Studio Code editor, a blog post or an email message? A typical workaround for that is to use the good old Notepad.exe as a buffer.

Now I have two dedicated hotkeys for that, Win+\ (paste as single line) and Win+Alt+\ (paste as multiple lines), which uniformly work across all apps and browsers.

Launch other applications with a custom hotkey

Windows Shell shortcuts have limits. It is difficult to find a hotkey combination that starts an application. For example, you cannot use a Win+Shift|Alt|Ctrl+Key combination. If you can assign a shortcut, the program can need as much as 10 seconds to start.

DevComrade does not have these limits. You can assign an action to almost all hotkey combinations. DevComrade supplies many actions that paste text and start applications. The default configuration has hotkeys for Windows Terminal and Visual Studio Code.

Custom actions

C# code in PredefinedHotkeyHandlers.cs supplies all actions.

To add a new action, add a hotkey element to the .config file. Set the name attribute to the name of the action; the actual hotkey is optional. For example, check out InsertGuid action, which types a new GUID such as {ED9C4E5F-1B2A-4C3D-9E8F-0A1B2C3D4E5F}:

<hotkey name="InsertGuid" menuItem="Insert &amp;Guid" />

This action has no hotkey. It can be invoked from the Win+F10 menu. To give the action a hotkey, add the mods and vkey attributes. This example adds Win+Alt+G:

<hotkey name="InsertGuid" menuItem="Insert &amp;Guid" mods="0x9" vkey="'G'" />

A hotkey element has these attributes:

Attribute Necessary Function
name Yes The name of the action. It must be the same as a method name in PredefinedHotkeyHandlers.
menuItem No The text for the Win+F10 menu. If you do not set it, the action does not show in the menu.
mods No The modifier keys. Alt = 1, Ctrl = 2, Shift = 4, Win = 8. Add the values together. See RegisterHotKey.
vkey No A virtual key code, or a character between single quotation marks, such as 'G'.
hasSeparator No Set this to true to put a separator line after the menu item.

How to give an action more than one hotkey

An action can have more than one hotkey. To do this, add a hotkey element for each key combination. Use the same name in each element. The ShowMenu action does this in the default configuration:

<hotkey name="ShowMenu" mods="0x8" vkey="0x79"/>
<hotkey name="ShowMenu" mods="0x9" vkey="0xBE"/>

Both Win+F10 and Win+Alt+. now open the main menu.

Set menuItem on only one of the elements. If you set it on more than one element, the menu shows the action more than one time.

The Roaming config has precedence over the Local config, and the rule applies to the full name. If the Roaming config has one or more elements with a given name, those elements replace all Local elements with that name. Thus, to change the hotkeys of an action, you must give all of them in the Roaming config.

These actions are available:

Name Function
PasteUnformatted Pastes the clipboard text with no formatting.
PasteAsSingleLine Pastes the clipboard text as one line.
PasteAsNumber Pastes only the digits and the decimal points.
PasteUnindented Pastes the clipboard text and removes the indentation.
PasteUnindentedUntabified Pastes the clipboard text. Removes the indentation and changes the tabs to spaces.
PasteToNotepad Puts the clipboard text into the built-in Notepad.
ConvertToPreformattedHtml Puts a <pre> tag around the clipboard text.
InsertGuid Types a new GUID.
OpenNotepad Opens the built-in Notepad.
OpenUrl Opens the URL from the clipboard in your web browser.
RunVSCode Starts Visual Studio Code in the current folder.
RunWindowsTerminal Starts Windows Terminal in the current folder.
RunWindowsTerminalAsAdmin Starts Windows Terminal as an administrator.
PresentationSettings Starts the Windows PresentationSettings.exe program.
ShowMenu Shows the DevComrade menu.

How to add a new action

Do these steps:

  1. Open PredefinedHotkeyHandlers.cs.
  2. Add a public method. Give the method the name of your action.
  3. Put the [HotkeyHandler] attribute on the method. DevComrade uses the method name and this attribute to find the action.
  4. Build the program again.
  5. Add a hotkey element with the same name to the .config file.

Your method must have the same parameters as this example:

[HotkeyHandler]
public async Task InsertGuid(Hotkey _, CancellationToken token)
{
    var text = Guid.NewGuid().ToString("B").ToUpper();

    await Host.FeedTextAsync(text, token);
    Host.PlayNotificationSound();
}

The Host property gives you the services of the program. Host is an IHotkeyHandlerHost. Use Host.FeedTextAsync to type text into the active window. Use Host.GetClipboardText and Host.SetClipboardText for the clipboard. Use Host.ShowNotepad for the built-in Notepad. Use Host.PlayNotificationSound to tell the user that the action is complete.

The token parameter is a CancellationToken. DevComrade cancels this token when the program stops. Give the token to each asynchronous method that you call.

How does it work?

When it comes to pasting text, DevComrade is different from many similar utilities (e.g., from the still-excellent Puretext) in how it uses Win32 simulated input API to elaborately feed the text into the currently active window, character by character, as though it was typed by a person. For example, it works well with Google's Secure Shell Chrome extension.

Work in progress

DevComrade is free and open-source software. The Apache License 2.0 applies to it. It is built with the .NET 10.0 SDK. It uses Windows Forms for the context menu.

I trust that the app is stable, but it's work in progress. One day, I may add a CI/CD logic to publish a WinGet package with a signed executable file. Until that, you can build the program from the source code. DevComrade does not collect telemetry, and it will never collect telemetry.

Try it out from the source code (it's easy)

  1. Download and install the .NET 10.0 SDK. This is the only tool that you must have. You do not need Visual Studio or Visual Studio Code to build the program.

  2. Get the source code. Download and unzip the source, or use git to clone the repository into a folder:

    mkdir DevComradeRepo && cd DevComradeRepo
    git clone https://github.com/postprintum/devcomrade .
    
  3. Build the program and start it:

    .\Package\make-and-run.bat
    

    You can also do these two steps yourself:

    dotnet publish -r win-x64 -c Release --self-contained .\DevComrade
    
    start .\DevComrade\bin\Release\net10.0-windows\win-x64\publish\DevComrade.exe
    

DevComrade has no main window. After it starts, it shows the DevComrade Icon icon in the system tray. Try these functions:

  • Press Win+F10 to see all the shortcuts and actions.
  • Copy some code to the clipboard. Then press Shift+Alt+Win+\ to paste the code into the built-in Notepad. Press Esc to hide the Notepad. Press Win+Alt+P to show it again.
  • Press Win+Alt+E to open Windows Terminal. Then press Win+\ to paste the clipboard text as one line. The terminal does not run the text until you press Enter.
  • Copy a URL to the clipboard. Spaces and line breaks in the URL are permitted. Then press Win+Alt+U to open the URL in your web browser.
  • Press Win+Alt+O to open Visual Studio Code in the current folder.

This tool has been built to suite my own personal habits; if it doesn't do something you think might be useful, feel free to tag me on Twitter.


DevComrade Win+F10 Menu


DevComrade Shift+Alt+Win+\ Notepad

About

DevComrade - A copy/paste/run productivity improvement utility for developers

Topics

Resources

Stars

257 stars

Watchers

6 watching

Forks

Contributors

Languages