If you use IronPython, you may already know that you can enable Tab completion and the use of colors in the console by starting ipy.exe with some special options

ipy.exe -X:TabCompletion -X:ColorfulConsole

Unfortunately these options are not used by the default shortcuts created when installing IronPython

image

 

Of course, it isn’t hard to manually create a shortcut. But because I frequently re-install the OS on my machines it becomes a bit tedious. Furthermore I have to repeat this procedure every time I install a new version of IronPython.

MY SOLUTION

Here’s my solution: a simple powershell script that automatically creates the shortcuts for me. The script is included below. Run it with Administrative privileges and it will create a new shortcut that enables tab completion and the colorful console.

image

 

And when you click on the shortcut you’ll see the effect immediately …

image

 

SOURCE CODE

#
# Creates console shortcuts to all installed IronPython versions.
# The shortcuts include tab-completion and colors.
#
# NOTE: Must be run with Administrator privileges
#

$shell = new-object -com "WScript.Shell"
$ipproducts = get-wmiobject Win32_Product | Where-Object { $_.Name -like "IronPython*" }
$startmenupath = $shell.SpecialFolders.Item("AllUsersStartMenu")
$workingdir  = $shell.SpecialFolders.Item("MyDocuments")

foreach ($p in $ipproducts)

    $link_folder =  $startmenupath
    $ipy_filename = join-path $p.InstallLocation "ipy.exe"
    $shortcut_path = join-path $startmenupath (join-path "Programs" $p.Name)
    if ( test-path $ipy_filename )
    {
        $link_filename = join-path $shortcut_path "IronPython Console (enhanced).lnk"
        $lnk = $shell.CreateShortcut($link_filename)
        $lnk.TargetPath = $p.InstallLocation + "ipy.exe"
        $lnk.Arguments = "-X:ColorfulConsole -X:TabCompletion"
        $lnk.WorkingDirectory = $workingdir
        $lnk.Save()   

    }
}

 

PARTING THOUGHTS

  • Why is the script in Powershell and not in IronPython? By relying on Powershell, I’m more certain you have the Powershell ISE (Integrated Scripting Environment) installed. And that means it’s easy to simply copy and paste this code and run it. There’s not a similar facility available for IronPython that I can rely on being present on so many windows machines.