Created
June 16, 2025 21:46
-
-
Save QuAzI/b031e63d70ae907289f55a8e5c927ea6 to your computer and use it in GitHub Desktop.
Some kind of interaction with tldr in 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 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