Skip to content

Commit

Permalink
Merge pull request dahlbyk#21 from nathanpalmer/HgFlowTabCompletion
Browse files Browse the repository at this point in the history
Added hg flow patterns to HgTabExpansion
  • Loading branch information
JeremySkinner committed Jan 23, 2013
2 parents 508c3e2 + 8c74833 commit 460e414
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions HgTabExpansion.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
$script:hgCommands = @()
$script:hgflowStreams = @()

function HgTabExpansion($lastBlock) {
switch -regex ($lastBlock) {
Expand Down Expand Up @@ -69,6 +70,17 @@ function HgTabExpansion($lastBlock) {
'hg commit (\S* )*-(I|X) (\S*)$' {
hgFiles $matches[3] 'M|A|R|!'
}

#handles hg flow * <branch name>
'hg flow (feature|release|hotfix|support) (\S*)$' {
findBranchOrBookmarkOrTags($matches[1]+"/"+$matches[2])
}

#handles hg flow *
'hg flow (\S*)$' {
hgflowStreams($matches[1])
hgLocalBranches($matches[1])
}
}
}

Expand Down Expand Up @@ -242,6 +254,50 @@ function thgCommands($filter) {
$cmdList | sort
}

function hgflowStreams($filter) {
if($script:hgflowStreams.Length -eq 0) {
$hgflow = ((hg root) + "\.flow")
if (Test-Path $hgflow) {
populatehgflowStreams($hgflow)
} else {
$hgflow = ((hg root) + "\.hgflow")
if (Test-Path $hgflow) {
populatehgflowStreams($hgflow)
}
}

$script:hgflowStreams = $script:hgflowStreams
}

if($filter) {
$hgflowStreams | ? { $_.StartsWith($filter) } | % { $_.Trim() } | sort
}
else {
$hgflowStreams | % { $_.Trim() } | sort
}
}

function populatehgflowStreams($filename) {
$ini = @{}

switch -regex -file $filename
{
"^\[(.+)\]" # Section
{
$section = $matches[1]
$ini[$section] = @()
}
"(.+?)\s*=(.*)" # Key
{
$name,$value = $matches[1..2]
$ini[$section] += $name
}
}

# Supporting by 0.4 and 0.9 files
$script:hgflowStreams = if ($ini["Basic"]) { $ini["Basic"] } else { $ini["branchname"] }
}

if (Get-Command "Register-TabExpansion" -errorAction SilentlyContinue)
{
Register-TabExpansion "hg.exe" -Type Command {
Expand Down

0 comments on commit 460e414

Please sign in to comment.