PowerShell script to install Custom Gallery for Doc. AutoSave

I got a note regarding the Visual Studio AutoSave extension saying they wished installing it were simpler.  I suspect they were referring to having to set up the custom gallery, rather than being able to get it from the Microsoft gallery.

I’m not ready to put it in the Microsoft gallery yet, so I toggled up a PowerShell script to add the registry key for the needed custom gallery.

This is specific to VS2013, but should be easy to modify for previous versions.

Run the script in a PowerShell console:
C:\> . CBExtensionRegKey.ps1
There is one optional parameter – DisplayName.  The default is “CB Gallery”; this is the name that will display in the list of galleries in VisStudio.

I have run it on Win7 and Win8.1; here are the entries made in the registry:

Registry key and values

Registry key and values

USE AT YOUR OWN RISK!

CBExtensionRegKey  (Rename to .ps1, of course.)

USE AT YOUR OWN RISK!

 

 

Stupid Word copy behavior

I want to copy a UNC path out of a document in Word and paste it in to an Explorer window.
I highlight the text I want to copy like this:

Highlight text to copy

Highlight text to copy

When I paste it, I get:
2) \\corp\xxx\data\xxx\installs\xxxxxxxx\Gateways\Archive

Why the hell was the “2)” included?  I did not highlight that because I did not want to copy it.

Sheesh.

 

Using TagBar and vim with .ini files

One application I work with uses a .ini file with over 30 sections.  I thought it would be handy to ‘outline’ that with tagbar.

In ctags.cnf, add:
–langdef=inifile
–langmap=inifile:.ini
–regex-inifile=/^\[([,&0-9A-Za-z ]+)\]/\1/s,section/
(I am still tuning the regex.  Please leave a comment if you have a better version…)

And in _vimrc:
let g:tagbar_type_dosini = {
\ ‘ctagstype’ : ‘inifile’,
\ ‘kinds’ : [
\ ‘s:section’
\ ]
\ }

In putting this together, I learned that in ‘tagbar_type_zzz‘, the ‘zzz’ is the vim string for a file type.  “:set ft” (in vim) reveals the file type for .ini files is ‘dosini’.

Tagbar lets you toggle between sorting the tags alphabetically and displaying them in the order they appear in the file.

Visual Studio AutoSave extension updated

Added an option to autosave Projects.

See the Utilities page for details.

Possible Issue:  I have been noticing strange behavior with the release build of the package installed in VS2013 running on Win8.1 — the menu text does not update as expected.  The extension works as desired, but it is confusing since the menu text doesn’t change once it is in a certain state.
I have been testing on Win7 and WinServer 2012 R2 (Azure VM!) and have not seen any problems.
I’d appreciate hearing from others that see any sort of unusual behavior…

(The version I have uploaded to the gallery is the release build; I install a debug build manually on my Win8.1 setup.)

Powershell Get-History and Invoke-History

I use Get-History (‘ghy’) and Invoke-History (‘ihy’) frequently, so I started thinking about streamlining their use.

I came up with Run-CmdFromHistory:
function Run-CmdFromHistory {
     param (
        [Parameter(Mandatory=$false)]
        [Int32] $cmdCnt = 15
    )
    $cmds=get-history | select -last $cmdCnt;
    $cmds;

    Write-Host “Enter a cmd id to run (empty to cancel)” -Foreground Yellow;
    $id = Read-Host ” “;
    if([string]::IsNullOrEmpty($id) -eq $false) {
        invoke-history $id;
    }
    else {
        “Canceled.”;
    }
<#

.SYNOPSIS A concatenation of Get-History/Invoke-History in one command. Display last cmdCnt number of commands. Allow user to select by number and run.

.PARAMETER cmdCnt (Optional) Number of commands to display. Default = 15.

#>
}
Set-Alias rch Run-CmdFromHistory -Scope “Global”

 

Vim, Tagbar, and PowerShell

I discovered a plugin named Tagbar that provides a sort of outline view of the elements in your script or source code file. For example, here is how C# is displayed:
tagbarCS

With a ctags.cnf file set up as described in a previous post, you need to add some information to your _vimrc to allow Tagbar to recognize tags for PowerShell.
In _vimrc:
let g:tagbar_type_ps1 = {
\ 'ctagstype' : 'powershell',
\ 'kinds' : [
\ 'f:function',
\ 'i:filter',
\ 'a:alias'
\ ]
\ }
(Note that the ‘f’, ‘i’, and ‘a’ match up with the end of the regex in ctags.cnf.)
Tell Tagbar where to find the Exuberant CTags executable, if it is not on your path:
let g:tagbar_ctags_bin='C:\ProgramData\chocolatey\bin\ctags.exe'

The result:
tagbarPS1

You can find Tagbar here: Tagbar