Some fixes to PowerLine prompt + New command

Start-GitHubDirDownload - Download a specific directory using
github's SVN support. Requires subversion package be installed.
This commit is contained in:
lksz 2021-10-11 21:16:43 -04:00
parent 86c1189211
commit 6ff3357c58
2 changed files with 67 additions and 3 deletions

View File

@ -1,7 +1,8 @@
Set-PowerLinePrompt -PowerLineFont
$local:MyPowerLineSetup = [ordered]@{ $local:MyPowerLineSetup = [ordered]@{
Title = { "Sz PS" } Title = { "Sz PS" }
SetCurrentDirectory = $true SetCurrentDirectory = $true
PowerLineFont = $true
RestoreVirtualTerminal = $true RestoreVirtualTerminal = $true
PowerLineCharacters = [ordered]@{ PowerLineCharacters = [ordered]@{
ColorSeparator = "$([char]::ConvertFromUtf32(0x2588) ColorSeparator = "$([char]::ConvertFromUtf32(0x2588)
@ -19,7 +20,7 @@ $local:MyPowerLineSetup = [ordered]@{
{ New-PromptText -EBg VioletRed4 $MyInvocation.HistoryId } { New-PromptText -EBg VioletRed4 $MyInvocation.HistoryId }
{ Get-Elapsed -Trim } { Get-Elapsed -Trim }
{ Get-SegmentedPath -LengthLimit 30 } { Get-SegmentedPath -LengthLimit 30 }
{ $local:_git_prompt = Write-VcsStatus; if( $_git_prompt ) { "$([PoshCode.Pansies.Entities]::ExtendedCharacters.Branch)$_git_prompt" } } { if( Get-GitStatus ) { "$([PoshCode.Pansies.Entities]::ExtendedCharacters.Branch)$(Write-VcsStatus)" } }
# Right-align block # Right-align block
{ "`t" } { "`t" }
@ -32,4 +33,6 @@ $local:MyPowerLineSetup = [ordered]@{
{ New-PromptText { "PS" } -Ebg Red } { New-PromptText { "PS" } -Ebg Red }
) )
} }
Set-PowerLineTheme @MyPowerLineSetup Set-PowerLinePrompt @MyPowerLineSetup
Write-Host -ForegroundColor Cyan "PowerLine Theme is ready, if you want to persist it, don't forget to run Export-PowerLinePrompt"

View File

@ -0,0 +1,61 @@
[CmdletBinding()]param(
[Parameter(Mandatory)]
[string]$GitHubProject,
[string]$Directory,
[string]$Destination='.',
[switch]$Update,
[string]$BackupRelativePath="<auto>"
)
$local:testReq = $(try {
Invoke-WebRequest "https://github.com/$GitHubProject/tree/HEAD/$Directory" -UseBasicParsing -ErrorAction Stop
} catch {})
if( 200 -ne $testReq.StatusCode ) {
Write-Verbose $($testReq|Format-List|Out-String)
Write-Error "Request failed for $GitHubProject : $Directory"
return
}
$DestFull = Get-Item $(Join-Path $Destination '.')
Write-Verbose "DestFull: $($DestFull | Format-List | Out-String)"
$local:tmpFile = ""
New-TemporaryFile | Select-Object -ExpandProperty FullName -OutVariable tmpFile | Remove-Item -Force
$tmpPath = New-Item -ItemType Directory $tmpFile
Remove-Variable tmpFile
Push-Location $tmpPath
Write-Verbose "tmp $($tmpPath.FullName) created"
if( $BackupRelativePath -eq "<auto>" ) {
$BackupRelativePath = ".overitten.on.#Timestamp#"
}
$BackupRelativePath = $BackupRelativePath -replace "#Timestamp#",$(Get-Date -Format "yyyyMMdd-HHmmss")
Write-Verbose "Fetching $Directory..."
$null = & svn checkout "https://github.com/$GitHubProject/trunk/$Directory"
$local:dirName = Split-Path -Leaf $Directory
Remove-Item -Recurse (Join-Path $dirName '.svn') -Force
Get-ChildItem -File -Force $dirName -Recurse | ForEach-Object {
$local:item = $_.FullName.Replace($tmpPath.FullName,'') -replace '^/',''
$local:dst = Join-Path $DestFull.FullName $item
if( Test-Path $dst ) {
if( -not $Update ) {
Write-Verbose "$dst already exists, skipping..."
return
}
if( -not (Compare-Object (Get-Content $item) (Get-Content $dst) -CaseSensitive) ) {
Write-Verbose "$dst already updated, skipping..."
return
}
$local:bkPath = Join-Path $DestFull.FullName (Split-Path -Parent $item) $BackupRelativePath (Split-Path -leaf $item)
$null = New-Item -ItemType Directory -Force (Split-Path -Parent $bkPath) -ErrorAction Stop
Move-Item -Force $dst $bkPath
}
Write-Verbose "Copy-Item -Force $_ $dst -PassThru"
Copy-Item -Force $_ $dst -PassThru
}
Pop-Location
Remove-Item -Recurse $tmpPath -Force