Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add VSCode settings.json file. #330

Merged
merged 3 commits into from
Dec 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"editor.insertSpaces": true,
"editor.tabSize": 4,
"editor.rulers": [ 120 ],
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"powershell.scriptAnalysis.settingsPath": "PSScriptAnalyzerSettings.psd1"
}
10 changes: 8 additions & 2 deletions GitPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,18 @@ if ($Host.UI.RawUI.BackgroundColor -eq [ConsoleColor]::DarkMagenta) {
$s.WorkingForegroundColor = $s.WorkingForegroundBrightColor
}

function Global:Write-VcsStatus { $Global:VcsPromptStatuses | foreach { & $_ } }
function Global:Write-VcsStatus {
$Global:VcsPromptStatuses | ForEach-Object { & $_ }
}

# Add scriptblock that will execute for Write-VcsStatus
$PoshGitVcsPrompt = {
$Global:GitStatus = Get-GitStatus
Write-GitStatus $GitStatus
}

# Install handler for removal/unload of the module
$Global:VcsPromptStatuses += $PoshGitVcsPrompt
$ExecutionContext.SessionState.Module.OnRemove = { $Global:VcsPromptStatuses = $Global:VcsPromptStatuses | ? { $_ -ne $PoshGitVcsPrompt} }
$ExecutionContext.SessionState.Module.OnRemove = {
$Global:VcsPromptStatuses = $Global:VcsPromptStatuses | Where-Object { $_ -ne $PoshGitVcsPrompt }
}
80 changes: 43 additions & 37 deletions GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@ $gitflowsubcommands = @{

function script:gitCmdOperations($commands, $command, $filter) {
$commands.$command -split ' ' |
where { $_ -like "$filter*" }
Where-Object { $_ -like "$filter*" }
}


$script:someCommands = @('add','am','annotate','archive','bisect','blame','branch','bundle','checkout','cherry','cherry-pick','citool','clean','clone','commit','config','describe','diff','difftool','fetch','format-patch','gc','grep','gui','help','init','instaweb','log','merge','mergetool','mv','notes','prune','pull','push','rebase','reflog','remote','rerere','reset','revert','rm','shortlog','show','stash','status','submodule','svn','tag','whatchanged')
$script:someCommands = @('add','am','annotate','archive','bisect','blame','branch','bundle','checkout','cherry',
'cherry-pick','citool','clean','clone','commit','config','describe','diff','difftool','fetch',
'format-patch','gc','grep','gui','help','init','instaweb','log','merge','mergetool','mv',
'notes','prune','pull','push','rebase','reflog','remote','rerere','reset','revert','rm',
'shortlog','show','stash','status','submodule','svn','tag','whatchanged')
try {
if ((git help -a 2>&1 | Select-String flow) -ne $null) {
if ($null -ne (git help -a 2>&1 | Select-String flow)) {
$script:someCommands += 'flow'
}
}
catch {
Write-Debug "Search for 'flow' in 'git help' output failed with error: $_"
}

function script:gitCommands($filter, $includeAliases) {
Expand All @@ -44,20 +49,20 @@ function script:gitCommands($filter, $includeAliases) {
$cmdList += $someCommands -like "$filter*"
} else {
$cmdList += git help --all |
where { $_ -match '^ \S.*' } |
foreach { $_.Split(' ', [StringSplitOptions]::RemoveEmptyEntries) } |
where { $_ -like "$filter*" }
Where-Object { $_ -match '^ \S.*' } |
ForEach-Object { $_.Split(' ', [StringSplitOptions]::RemoveEmptyEntries) } |
Where-Object { $_ -like "$filter*" }
}

if ($includeAliases) {
$cmdList += gitAliases $filter
}
$cmdList | sort
$cmdList | Sort-Object
}

function script:gitRemotes($filter) {
git remote |
where { $_ -like "$filter*" }
Where-Object { $_ -like "$filter*" }
}

function script:gitBranches($filter, $includeHEAD = $false) {
Expand All @@ -66,49 +71,49 @@ function script:gitBranches($filter, $includeHEAD = $false) {
$prefix = $matches['from']
$filter = $matches['to']
}
$branches = @(git branch --no-color | foreach { if($_ -match "^\*?\s*(?<ref>.*)") { $matches['ref'] } }) +
@(git branch --no-color -r | foreach { if($_ -match "^ (?<ref>\S+)(?: -> .+)?") { $matches['ref'] } }) +
$branches = @(git branch --no-color | ForEach-Object { if($_ -match "^\*?\s*(?<ref>.*)") { $matches['ref'] } }) +
@(git branch --no-color -r | ForEach-Object { if($_ -match "^ (?<ref>\S+)(?: -> .+)?") { $matches['ref'] } }) +
@(if ($includeHEAD) { 'HEAD','FETCH_HEAD','ORIG_HEAD','MERGE_HEAD' })
$branches |
where { $_ -ne '(no branch)' -and $_ -like "$filter*" } |
foreach { $prefix + $_ }
Where-Object { $_ -ne '(no branch)' -and $_ -like "$filter*" } |
ForEach-Object { $prefix + $_ }
}

function script:gitTags($filter) {
git tag |
where { $_ -like "$filter*" }
Where-Object { $_ -like "$filter*" }
}

function script:gitFeatures($filter, $command){
$featurePrefix = git config --local --get "gitflow.prefix.$command"
$branches = @(git branch --no-color | foreach { if($_ -match "^\*?\s*$featurePrefix(?<ref>.*)") { $matches['ref'] } })
$branches = @(git branch --no-color | ForEach-Object { if($_ -match "^\*?\s*$featurePrefix(?<ref>.*)") { $matches['ref'] } })
$branches |
where { $_ -ne '(no branch)' -and $_ -like "$filter*" } |
foreach { $prefix + $_ }
Where-Object { $_ -ne '(no branch)' -and $_ -like "$filter*" } |
ForEach-Object { $prefix + $_ }
}

function script:gitRemoteBranches($remote, $ref, $filter) {
git branch --no-color -r |
where { $_ -like " $remote/$filter*" } |
foreach { $ref + ($_ -replace " $remote/","") }
Where-Object { $_ -like " $remote/$filter*" } |
ForEach-Object { $ref + ($_ -replace " $remote/","") }
}

function script:gitStashes($filter) {
(git stash list) -replace ':.*','' |
where { $_ -like "$filter*" } |
foreach { "'$_'" }
Where-Object { $_ -like "$filter*" } |
ForEach-Object { "'$_'" }
}

function script:gitTfsShelvesets($filter) {
(git tfs shelve-list) |
where { $_ -like "$filter*" } |
foreach { "'$_'" }
Where-Object { $_ -like "$filter*" } |
ForEach-Object { "'$_'" }
}

function script:gitFiles($filter, $files) {
$files | sort |
where { $_ -like "$filter*" } |
foreach { if($_ -like '* *') { "'$_'" } else { $_ } }
$files | Sort-Object |
Where-Object { $_ -like "$filter*" } |
ForEach-Object { if($_ -like '* *') { "'$_'" } else { $_ } }
}

function script:gitIndex($filter) {
Expand All @@ -126,7 +131,8 @@ function script:gitCheckoutFiles($filter) {
function script:gitDiffFiles($filter, $staged) {
if ($staged) {
gitFiles $filter $GitStatus.Index.Modified
} else {
}
else {
gitFiles $filter (@($GitStatus.Working.Unmerged) + @($GitStatus.Working.Modified) + @($GitStatus.Index.Modified))
}
}
Expand All @@ -140,38 +146,39 @@ function script:gitDeleted($filter) {
}

function script:gitAliases($filter) {
git config --get-regexp ^alias\. | foreach {
git config --get-regexp ^alias\. | ForEach-Object{
if($_ -match "^alias\.(?<alias>\S+) .*") {
$alias = $Matches['alias']
if($alias -like "$filter*") {
$alias
}
}
} | Sort
} | Sort-Object
}

function script:expandGitAlias($cmd, $rest) {
if((git config --get-regexp "^alias\.$cmd`$") -match "^alias\.$cmd (?<cmd>[^!].*)`$") {
if ((git config --get-regexp "^alias\.$cmd`$") -match "^alias\.$cmd (?<cmd>[^!].*)`$") {
return "git $($Matches['cmd'])$rest"
} else {
}
else {
return "git $cmd$rest"
}
}

function GitTabExpansion($lastBlock) {

if($lastBlock -match "^$(Get-AliasPattern git) (?<cmd>\S+)(?<args> .*)$") {
if ($lastBlock -match "^$(Get-AliasPattern git) (?<cmd>\S+)(?<args> .*)$") {
$lastBlock = expandGitAlias $Matches['cmd'] $Matches['args']
}

# Handles tgit <command> (tortoisegit)
if($lastBlock -match "^$(Get-AliasPattern tgit) (?<cmd>\S*)$") {
# Need return statement to prevent fall-through.
return $tortoiseGitCommands | where { $_ -like "$($matches['cmd'])*" }
if ($lastBlock -match "^$(Get-AliasPattern tgit) (?<cmd>\S*)$") {
# Need return statement to prevent fall-through.
return $tortoiseGitCommands | Where-Object { $_ -like "$($matches['cmd'])*" }
}

# Handles gitk
if($lastBlock -match "^$(Get-AliasPattern gitk).* (?<ref>\S*)$"){
if ($lastBlock -match "^$(Get-AliasPattern gitk).* (?<ref>\S*)$"){
return gitBranches $matches['ref'] $true
}

Expand Down Expand Up @@ -293,8 +300,7 @@ function GitTabExpansion($lastBlock) {
}

$PowerTab_RegisterTabExpansion = if (Get-Module -Name powertab) { Get-Command Register-TabExpansion -Module powertab -ErrorAction SilentlyContinue }
if ($PowerTab_RegisterTabExpansion)
{
if ($PowerTab_RegisterTabExpansion) {
& $PowerTab_RegisterTabExpansion "git.exe" -Type Command {
param($Context, [ref]$TabExpansionHasOutput, [ref]$QuoteSpaces) # 1:

Expand Down
32 changes: 32 additions & 0 deletions PSScriptAnalyzerSettings.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@{
# Use Severity when you want to limit the generated diagnostic records to a
# subset of: Error, Warning and Information.
# Uncomment the following line if you only want Errors and Warnings but
# not Information diagnostic records.
Severity = @('Error','Warning')

# Use IncludeRules when you want to run only a subset of the default rule set.
#IncludeRules = @('PSAvoidDefaultValueSwitchParameter',
# 'PSMissingModuleManifestField',
# 'PSReservedCmdletChar',
# 'PSReservedParams',
# 'PSShouldProcess',
# 'PSUseApprovedVerbs',
# 'PSUseDeclaredVarsMoreThanAssigments')

# Use ExcludeRules when you want to run most of the default set of rules except
# for a few rules you wish to "exclude". Note: if a rule is in both IncludeRules
# and ExcludeRules, the rule will be excluded.
ExcludeRules = @('PSAvoidUsingWriteHost', 'PSAvoidGlobalVars')

# You can use the following entry to supply parameters to rules that take parameters.
# For instance, the PSAvoidUsingCmdletAliases rule takes a whitelist for aliases you
# want to allow.
Rules = @{
# Do not flag 'cd' alias.
# PSAvoidUsingCmdletAliases = @{Whitelist = @('cd')}

# Check if your script uses cmdlets that are compatible on PowerShell Core, version 6.0.0-alpha, on Linux.
# PSUseCompatibleCmdlets = @{Compatibility = @("core-6.0.0-alpha-linux")}
}
}
2 changes: 1 addition & 1 deletion Utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function Get-LocalOrParentPath($path) {
if ($checkIn.PSProvider.Name -ne 'FileSystem') {
return $null
}
while ($checkIn -ne $NULL) {
while ($null -ne $checkIn) {
$pathToTest = [System.IO.Path]::Combine($checkIn.fullname, $path)
if (Test-Path -LiteralPath $pathToTest) {
return $pathToTest
Expand Down