feat(toolkit): use the folder picker for launcher path prompts
Move the fzf folder browser to Scripts/Private/Select-FolderPath.ps1 so the launcher can use it too. Full tenant export root, tenant A and B export folders and the report folder of the offline compare, the earlier-export choice of the drift check and the report paths now open the picker. It starts at the nearest existing folder, falls back to a plain prompt without fzf and understands ~ and quotes.
This commit is contained in:
@@ -107,49 +107,7 @@ function Select-MenuItem
|
||||
return Show-NumberedMenu -Items $Items -Header $Header -Multi:$Multi
|
||||
}
|
||||
|
||||
function Select-FolderPath
|
||||
{
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[string]$Prompt,
|
||||
[string]$StartPath = (Get-Location).Path
|
||||
)
|
||||
if(-not (Test-FzfAvailable))
|
||||
{
|
||||
return Read-Host $Prompt
|
||||
}
|
||||
|
||||
$current = if(Test-Path -LiteralPath $StartPath) { (Resolve-Path -LiteralPath $StartPath).Path } else { (Get-Location).Path }
|
||||
|
||||
while($true)
|
||||
{
|
||||
$entries = @("[Use this folder]", "[Create new folder]", "[Type path manually]")
|
||||
$parent = Split-Path -Path $current -Parent
|
||||
if($parent) { $entries += ".." }
|
||||
$subdirs = Get-ChildItem -LiteralPath $current -Directory -ErrorAction SilentlyContinue | Sort-Object Name | ForEach-Object { "$($_.Name)/" }
|
||||
$entries += $subdirs
|
||||
|
||||
$choice = $entries | fzf --header="$Prompt [current: $current]"
|
||||
if(-not $choice) { return $null }
|
||||
|
||||
switch ($choice)
|
||||
{
|
||||
"[Use this folder]" { return $current }
|
||||
"[Create new folder]" {
|
||||
$name = (Read-Host "New folder name (inside $current)").Trim()
|
||||
if([string]::IsNullOrWhiteSpace($name)) { continue }
|
||||
if($name.IndexOfAny([IO.Path]::GetInvalidFileNameChars()) -ge 0) { Write-Host "Invalid folder name." -ForegroundColor Yellow; continue }
|
||||
$newPath = Join-Path $current $name
|
||||
try { New-Item -ItemType Directory -Path $newPath -Force -ErrorAction Stop | Out-Null; $current = $newPath }
|
||||
catch { Write-Host "Could not create folder: $($_.Exception.Message)" -ForegroundColor Yellow }
|
||||
continue
|
||||
}
|
||||
"[Type path manually]" { $typed = Read-Host "Enter path"; if(-not [string]::IsNullOrWhiteSpace($typed)) { return $typed }; continue }
|
||||
".." { $current = $parent; continue }
|
||||
default { $current = Join-Path $current ($choice.TrimEnd('/')); continue }
|
||||
}
|
||||
}
|
||||
}
|
||||
. (Join-Path $PSScriptRoot "Select-FolderPath.ps1")
|
||||
|
||||
function Read-YesNo
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user