the home row

the home row | January 2010

Convert a path or file name to Dos 8.3 format with AutoHotkey

by Rob 28. January 2010 05:36

It comes about now and again that you need to get an old style Dos 8.3 file or path name to satisfy some legacy application or to represent a standard path without the blank spaces in it. Here's an example of a Dos 8.3 path to Spotify in my Dropbox:

C:\Mydrop~1\Apps\spotify\spotify.exe

The path you'd normally see would be:

C:\My Dropbox\Apps\spotify\spotify.exe

If I tried to launch the normal link from the command line it'd fail because it wouldn't be able to resolve the path correctly.

But using the shortened Dos version causes no problems because it doesn't contain any spaces. So rather than trying to wrap the standard path in quotes for a program that isn't expecting spaces you can pass the Dos 8.3 path instead.

Here's an AutoHotkey script that will take the current highlighted text, copy it to the clipboard, convert it to the Dos 8.3 path and paste back to the clipboard.

capslock & d::
Send ^c
ClipWait,1
If Errorlevel
{
    MsgBox, Error copying to the clipboard!
    return
}

newPath := GetShortPath(Clipboard)
if newPath =
{
    MsgBox, To Dos Path - Invalid source path!
}

Clipboard := newPath
ClipWait, 1
If Errorlevel
{
    MsgBox, Error pasting to the clipboard!
    return
}

return

GetShortPath(LongPath) {
Loop, %LongPath%, 1
Return A_LoopFileShortpath
}

The script is fired by pressing capslock & d. If the path is incorrect, there are problems accessing the clipboard or no text is highlighted the script will inform you with a message box. If everything goes as planned then the new shortened path will be silently copied to the clipboard. Take a look at the AutoHotkey documentation if you’d like to change this to a different keyboard shortcut.

Tags:

Visual Studio 2010: Remapping - Move between highlighted references

by Rob 24. January 2010 17:13

I've recently been following the Is This Thing On - Visual Studio 2010 tip of the day series. I highly recommend subscribing. The best tip yet was around Reference highlighting. In a nut shell every time you move over a symbol all instances are highlighted. You can see below that all references have been highlighted for MainWindow:

image

Once the symbols have been highlighted you can move to the next occurrence with Ctrl+Shift+Down Arrow and move to the previous occurrence with Ctrl+Shift+Up Arrow. For ViEmu users it will be unnatural to reach over for the arrow keys, so it's time to remap these using AutoHotkey. The idea is based on this blog post by JP Boodhoo where he maps ReSharper Go to next member to Alt+J and ReSharper Go to Previous Member to Alt+K. So here’s the update you need for your AutoHotkey script:

$^+k:: send, ^+{up}

$^+j:: send, ^+{down}

This will map Ctrl+Shift+J to Ctrl+Shift+Down Arrow and Ctrl+Shift+K to Ctrl+Shift+Up Arrow. Now you can happily move between highlighted references without leaving the home row.

Enjoy

Tags: ,

Open a file into an existing instance of GVim

by Rob 16. January 2010 14:47

I use GVim a lot for editing most types of files. More than likely I'll launch files straight from a command line. One problem with this method is that each file appears in a new instance of GVim. This can quickly become difficult to manage. You can solve this problem by using the clientserver feature of GVim. Below is what the documentation says about clientserver functionality.

When compiled with the |+clientserver| option, Vim can act as a command server. It accepts messages from a client and executes them.

This means that your shell of choice can act as a client and fire commands to an existing instance of GVim. I use PowerShell ISE for simple file operations and launch all my programs from there. To launch a named server instance of GVim I run the following command:

C:\Mydrop~1\Apps\gVimPortable\gVimPortable.exe --servername gvim

I keep GVim in my DropBoxso it moves with me to other computers. So you'll need to edit the path to the location of GVim on your computer. The servername argument is set to the name gvim, but you can set this to anything you like.

Now when you wish to open a new tab in this instance run the following command:

C:\Mydrop~1\Apps\gVimPortable\gVimPortable.exe --servername GVIM --remote-tab .\main.ahk

In my case this launches the main AutoHotkey script into a new tab in the existing instance of GVim. You may be thinking this will mean more typing and ultimately take more time. To speed this whole process up I store a couple of snippets in an AutoHotkey script. This allows me to type "gvit" and expand this out to:

C:\Mydrop~1\Apps\gVimPortable\gVimPortable.exe --servername GVIM --remote-tab

I can then just add the file name to the end of the command to launch into my gvim instance. Not everyone's cup of tea, but I hope someone will find this useful. To find out more about snippets in AutoHotkey you can take a look at another of my blog posts.

 

del.icio.us Tags: ,

Tags: ,

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen