-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PowerShell snippet to run onefetch on directory change can break tools that wrap Set-Location
(cd
)
#1467
Comments
I think I know what the problem is for Yazi (and likely zoxide, too). Yazi has this recommended wrapper for PowerShell to CD into the last directory used: function y {
$tmp = [System.IO.Path]::GetTempFileName()
yazi $args --cwd-file="$tmp"
$cwd = Get-Content -Path $tmp
if (-not [String]::IsNullOrEmpty($cwd) -and $cwd -ne $PWD.Path) {
Set-Location -LiteralPath $cwd
}
Remove-Item -Path $tmp
} I don't know much PowerShell, but I'm guessing that @Wu-Felix's issue is caused because the custom Perhaps this can be easily fixed by accepting and passing any parameter from the custom function Set-Location-Proxy {
# do something
Set-Location @args
} cc @kiapanahi I'd happily accept a PR from either of you 🙂 |
Set-Location
(cd
)Set-Location
(cd
)
@spenserblack I was working with $global:lastRepository = $null
function Check-DirectoryForNewRepository {
$currentRepository = git rev-parse --show-toplevel 2>$null
if ($currentRepository -and ($currentRepository -ne $global:lastRepository)) {
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
onefetch | Write-Host
}
$global:lastRepository = $currentRepository
}
function Set-Location {
param (
[string]$Path,
[string]$LiteralPath
)
if ($LiteralPath) {
Microsoft.PowerShell.Management\Set-Location -LiteralPath $LiteralPath
}
else {
Microsoft.PowerShell.Management\Set-Location -Path $Path
}
Check-DirectoryForNewRepository
}
Check-DirectoryForNewRepository Added an extra parameter to handle the Output |
@FallenDeity Looks good! I have some feedback about the code block, but if you'd like to make a PR I can save my feedback for that. |
Closed by #1542 |
Originally posted by @Wu-Felix in #1452 (comment)
The text was updated successfully, but these errors were encountered: