June 2011

I started my blog back in December 2010 and it's still going strong. I've posted at least once post a month since then, so feel free to browse through the archives.

Fix for Italic Fonts in Windows Command Prompt

I kept getting a problem where the Consolas font was in italics on when using either CMD or PowerShell on Windows 7.

After messing around with lots of options, I actually ran a repair on the Office 2010 installation I had. It worked. I’m not exactly sure why this is the case, but if you’ve got this problem – you might want to try this too.

I know Consolas ships with Office 2010, so maybe the repair just makes sure the font files are installed correctly. If anyone knows the real reason, please feel free to leave me a comment!

Sharpie Pen & Liquid Pencil

We all know and love the original Sharpie marker. It’s an absolute modern classic, but what’s more interesting is the addition of the Sharpie Pen, and the Liquid Pencil…

Sharpie Pen

I only recently got the Sharpie Pen Retractable, but already I like it. True, the barrel is a little fat which tends to make the very fine tip look a bit funny, but overall the experience is good. The ink seems to be very nice and does not bleed through my Post-It notes. Though I do worry that the ink will dry out, and I’ll have to wait and see if this is the case…

I have noticed that there is a slightly updated version of this pen on the Sharpie website, I think I may prefer the newer barrel design, but I don’t think there’s going to be enough in it for me to get one just yet.

Sharpie Liquid Pencil

The Sharpie Liquid Pencil (which I believe may now be discontinued) uses a liquid graphite ‘ink’, which writes like a pen, but is erasable like a pencil. The idea is that you’ll no longer have any broken leads, or something. I think the idea is just to reinvent a classic in a whole new way. A bit like technology… for the sake of technology.

I’m so glad I have this pencil – the idea is very cool, even though the execution is a little off. Unfortunately the lines come out blotchy and not very consistent… but bonus points are given because of the cool technology inside. Though the truth is that I always gravitate back to my real mechanical pencil after using the Sharpie Liquid Pencil a short amount of time.

Above all, Stanford has shown us that Sharpie is capable of being much more than just a marker. They have probably played a slightly safer move by adding these risky and experimental products to a brand that is seen as cool by the younger generations anyway, and as far as I’m concerned they can keep doing this – even if the product doesn’t turn out as well as hoped. I think this is especially important for an American brand, as the Japanese seem to excel at this naturally.

Update…

While the Sharpie Pen started out well, the more I’ve used it the less I’ve liked the barrel. It’s too fat and and the rubber grip is too solid to be worth having. The ink is still very good though!

Outlook Tasks in PowerShell and Vim

Getting Outlook Tasks in PowerShell is actually pretty easy. All you need to do is use the Office Interop to get access to the default tasks folder, then iterate through the items that are returned.

Create a file called Get-OutlookTask.ps1 in your scripts folder, and paste the following code:

Add-Type -AssemblyName Microsoft.Office.Interop.Outlook
$folders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
$outlook = New-Object -ComObject outlook.application
$mapi = $outlook.GetNameSpace("mapi")
$tasks = $mapi.getDefaultFolder($folders::olFolderTasks)

foreach($task in $tasks.Items)
{
  if(!$task.complete)
  { 
    $task.subject 
  }
}

Naturally, you could customize this script to work any way you like – for example, you could sort by priorty or date, or you could show an extra column for category information. I have actually set up an alias to this script, so all I have to do is type tasks to see all my current tasks.

If you have set Vim to work with PowerShell, you can import your Outlook Tasks directly into the open document by using the Vim command:

:r! tasks

Pretty cool huh? If you’re looking to add Outlook Tasks in a similar way, you can check out this script by Lee Holmes. I use this one with the alias of nt to save on all that extra typing.

If you want to be able to add Outlook Tasks from Vim, I suggest you add the following function to your vimrc file:

function! Task(args)
  system("nt \\\"" . a:args . "\\\"")
endfunction

command! -nargs=1 Task :call Task('')

Now you just need to call :Task buy milk and it’ll get added – without switching to the shell itself.

Writing and Running F# Scripts with Vim

When I’m writing software for the .NET Framework I tend to have a copy of F# Interactive open. This lets me run commands directly like so…

This is fine for simple stuff, but if you’re writing something a little more complex it’s better to write a script. In the past I’ve done this by having another copy of Visual Studio open and running the script that way. This works really well, and includes colour coding, intellisense and all the other good stuff you expect.

However there are times that having yet another copy of Visual Studio is a little heavy for just keeping track of a script. Enter Vim, the de facto command line editor for Unix and other operating systems.

  1. Set up Vim to work with PowerShell
  2. Grab yourself a copy of the F# Syntax file
  3. Save it into your Vim plugins directory
  4. Add the following lines to your vimrc file…
au BufRead,BufNewFile *.fs set filetype=fs
au BufRead,BufNewFile *.fsx set filetype=fs

Now when you create a .fsx file, you can run it directly from F# Interactive by using Vim’s shell execution feature.

:!fsi %

This will run your script in F# Interactive and present you with the results. The :! Vim command is for running the external program, and the % represents the filename of the currently open document.

Note that you’ll need to have set up F# Interactive by either adding it to the path or setting an alias in PowerShell. If you haven’t done this already, you can do it by adding the following lines to your PowerShell profile:

$FSIPATH     = "C:\Program Files (x86)\Microsoft F#\v4.0\Fsi.exe"

Set-Alias fsi  $FSIPATH

Setting up Vim to work with PowerShell

As an avid console user, I like being able to edit text without opening an interface that requires a mouse. For me this text editor is Vim – the extremely well regarded editor that ships with a very large number of operating systems.

My command line of choice is PowerShell, and I set up any extra commands to live in a Scripts directory inside my Windows user directory. If you’d like to do this you need to download Vim to the Scripts directory, then edit your PowerShell profile to include an alias so you can access Vim from any directory you might be in, as well as a couple of commands to make editing common files even simpler.

# There's usually much more than this in my profile!
$SCRIPTPATH = "C:\Users\Julian\Scripts"
$VIMPATH    = $SCRIPTPATH + "\vim73\vim.exe"

Set-Alias vi   $VIMPATH
Set-Alias vim  $VIMPATH

# for editing your PowerShell profile
Function Edit-Profile
{
    vim $profile
}

# for editing your Vim settings
Function Edit-Vimrc
{
    vim $home\_vimrc
}

Then you need to set Vim up in the way you like it, there are lots of sites with suggestions for how to set your vimrc file, but for now I’m just going to suggest you add a link back to PowerShell by adding the following lines:

set shell=powershell
set shellcmdflag=-command

This means that when you run the :shell command in Vim, you will actually use PowerShell itself to run commands, including all the aliases you set in your profile. I find this especially handy for writing and running F# scripts, as well as task management with Outlook – both of which I’ll write about in posts this week, but you can test this out now by running :sh or :!get-childitem | more and seeing what happens!