Skip to content

Instantly share code, notes, and snippets.

@QuAzI
Last active July 1, 2025 11:15
Show Gist options
  • Save QuAzI/b031e63d70ae907289f55a8e5c927ea6 to your computer and use it in GitHub Desktop.
Save QuAzI/b031e63d70ae907289f55a8e5c927ea6 to your computer and use it in GitHub Desktop.
Fast fuzzy help search with tldr on Windows
# 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
@QuAzI
Copy link
Author

QuAzI commented Jul 1, 2025

I hope I will improve this flow to show

  • notes from user
  • standard notes from TLDR
  • man page
  • search engine or AI if all previous failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment