Seobiseu 1.10

Illustration

New version is here. Those missing restart option can now rejoice. Restart is available in both context menu on main screen and in notification area.

Download is available here.

P.S. Restart option is not on main menu itself since it makes it a little crowded.

Multi-mercurial

I believe that ideal setup for Mercurial is one project per repository. Most of time this is really good setup but occasionally it will cause problems. Whenever I need to do same thing on multiple repositories (e.g. push) there is an issue. Better said, there was an issue before I created HgAll script.

Script is written in PowerShell and does two things. First it traverses all directories bellow current (or defined) one and finds all mercurial repositories. Then it forwards whatever is on command line as parameter to hg command line utility. In effect it executes same command to each repository it finds.

HgAll [StartingFolder] [commands]

HgAll C:\Source summary
HgAll push all

First example will start search from C:\Source and execute “hg summary” command for any Mercurial folder found. Second example will start in current directory and execute “hg push all”.

You can download script here (or take a peek at source bellow):

$StartupLocation = (Get-Location -PSProvider FileSystem).ProviderPath

$Folder = $Null;
$Command = ""
foreach ($arg in $args) {
    if ($Folder -eq $Null) {
        if ((Test-Path -Path $arg -PathType Container) -eq $True) {
            $Folder = (Resolve-Path -Path $arg).Path
            $Command = ""
        } else {
            $Folder = $StartupLocation
            $Command = $arg
        }
    } else {
        if ($Command.length -ne 0) { $Command += " " }
        $Command += $arg
    }
}

if ($Command.length -eq 0) {
    $Command = "summary"
}

function Traverse([string]$path) {
    Write-Debug $path
    $dirs = Get-ChildItem $path | Where {$_.psIsContainer -eq $true}

    if ($dirs -ne $Null) {
        foreach ($dir in $dirs) {
            $hgsubdir = Join-Path -Path $dir.FullName -ChildPath .hg
            if ((Test-Path -Path $hgsubdir -PathType Container) -eq $True) {
                $hgdir = $dir.FullName
                if ($Command.length -ne 0) {
                    Set-Location $hgdir
                    Write-Host
                    $result = Invoke-Expression "hg $Command 2>&1"
                    if (($LASTEXITCODE -ne 0) -or (!$?)) {
                        Write-Host $dir.Name
                        foreach ($line in $result) {
                            Write-Warning $line
                        }
                    } else {
                        Write-Output $dir.Name
                        foreach ($line in $result) {
                            Write-Host $line
                        }
                    }
                }
            } else {
                Traverse($dir.FullName)
            }
        }
    }
}


try {
    Traverse($Folder)
} finally {
    Set-Location $StartupLocation
}

Running PowerShell

I mostly use PowerShell for my scripting needs. However, I am so used to old command prompt that I type cmd.exe without thinking. So, instead of changing my habits, I have .bat file for each PowerShell script:

powershell script.ps1 %*

First and second parameter determine what to run and third parameter forwards all command line arguments to script.

Are You Sure?

Illustration

Like a true member of “old guard” I occasionally touch hosts file in order to do custom redirects. On Windows 7 it is annoying experience to edit this file. First you need to open it directly in program since it doesn’t have proper extension. After short edit you need to save it and, of course, it is protected file. So you need to open another instance of notepad, this time with administrative privileges…

Few weeks after you change this you might get dialog informing you of virus. True, it doesn’t say virus as such but it does look threatening. Warning message even has virus-like name. Only after careful reading it is obvious that two added lines caused this mess:

127.0.0.1	www.google-analytics.com
127.0.0.1	ssl.google-analytics.com

Security essentials detected this as a thread and, if you use default disinfect command, it will restore order to your hosts file - by deleting one of those items. Redirecting www.google-analytics.com is a big threat but ssl.google-analytics.com is fair game…

Solution is simple, just select allow option and everything is good once more. At least for a month or so. Then, out of a blue, Security Essentials might warn you about something you did before and you already forgot all about it.