Skip to content

Instantly share code, notes, and snippets.

@QuAzI
Created June 16, 2025 21:46
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.
Some kind of interaction with tldr in Windows
# this script helps to yank specific command shown by tldr into clipboard
$command = @(tldr.exe --list-all |
Sort-Object |
Get-Unique |
fzf.exe --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'
)
if ($command -ne $null)
{
$temp = New-TemporaryFile
tldr -q $command | nvim -i NONE -c "set buftype=nofile" -c "autocmd VimLeave * call writefile([getreg('')], '$temp')" -
$buffer = Get-Content $temp
Remove-Item $temp
if ([string]::IsNullOrEmpty($buffer))
{
Set-Clipboard -Value $command
}
else
{
Set-Clipboard -Value $buffer
}
}
# BUG: new-lines trimmed in multiline selections
# BUG: trim spaces required for singleline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment