Last active
July 1, 2025 11:15
-
-
Save QuAzI/b031e63d70ae907289f55a8e5c927ea6 to your computer and use it in GitHub Desktop.
Fast fuzzy help search with tldr on Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this script helps to yank specific command shown by tlrc (tldr in Rust) into clipboard or to get help from AI | |
# tldr, fzf, nvim and aichat required in %PATH% | |
$command = $args | |
& tldr.exe --list-all | | |
Sort-Object | | |
Get-Unique | | |
fzf.exe -q "$command" --preview 'tldr --color always {1}' --preview-window=right,70% --bind 'ctrl-y:execute-silent(tldr.exe {1} | Set-Clipboard)' --with-shell 'powershell.exe -NoLogo -NonInteractive -NoProfile -Command' | | |
%{ | |
$command = $_ | |
if ($command -ne $null) | |
{ | |
$temp = New-TemporaryFile | |
Start-Process -NoNewWindow -Wait -FilePath "powershell.exe" -ArgumentList "-NoProfile", "-Command", "tldr -q $command | nvim -R -n -i NONE +'nnoremap q :q!<CR>' -c 'set buftype=nofile' -c 'set ffs=dos' -c 'autocmd VimLeave * call writefile([getreg('''')], ''$temp'')' -" | |
$buffer = "" | |
if ($temp.Length -gt 0) { | |
$buffer = Get-Content -Raw -Path $temp.FullName | |
$buffer = ($buffer -split "`0" -join "`n") | |
} | |
Remove-Item $temp | |
if ([string]::IsNullOrWhiteSpace($buffer)) | |
{ | |
$buffer = $command | |
} | |
$buffer = $buffer.TrimStart().TrimEnd() | |
Out-Default | |
Set-Clipboard -Value ([string]$buffer) | |
[Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory($buffer) | |
Write-Output "$buffer" | |
exit 0 | |
} else { | |
Write-Host "Undefined behavior: $args" | |
} | |
} | |
# tldr fails to find those | |
#Write-Host "Let use AI for: $command" | |
& aichat $args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I hope I will improve this flow to show