AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Pbcopy ssh key8/26/2023 ![]() ![]() I hope pbcopy and pbpaste will help improve your everyday terminal workflow, just as they have for me. Pipes make it trivial to connect clipboard commands to most command-line tools, such as gh for creating Gists from the clipboard, or uuidgen for copying random UUID values. In this article, we created similar commands for WSL as command-line aliases.Ī big advantage of clipboard command-line tools is being able to copy from and paste to other commands using pipes, and to and from files using redirects. macOS comes with the built-in pbcopy and pbpaste commands, but getting the same functionality when running a Linux shell with WSL isn't as obvious. Clipboard command-line tools avoid many of these issues and integrate nicely with other tools. Manually copying and pasting in the terminal is fraught with problems and annoyances. With the help of PowerShell, WSL, Linux, and just two lines of code, we now have commands for copying and pasting in the Linux shell. ![]() Open Windows PowerShell or Windows Terminal to try out the following PowerShell commands:Īt last, we've arrived back where we began in Getting Started. This means we should be able to access the clipboard from WSL by using Windows command-line clipboard tools.Ĭonveniently, the PowerShell shell – which comes pre-installed with Windows – has just what we're looking for. worry about copying too many or too few charactersīefore wrapping up, let's take a look at how the clipboard aliases are implemented.add quotes and escape characters when pasting.remove extra newlines when copying multiple lines.When using the aliases you don't have to: ![]() The aliases solve many pitfalls of manual copy and paste in the terminal. In the previous sections, we've seen how the aliases make using the clipboard in the terminal more streamlined and enjoyable. Creating aliases in the shell is done with the alias command:Įnter fullscreen mode Exit fullscreen mode pbcopy sets the clipboard contents from its input, and pbpaste outputs it. We're going to define two aliases in our WSL Linux shell. Luckily, we can easily add our own pbcopy and pbpaste commands to WSL with a couple of one-liner command-line aliases. So understandably, I felt bummed out when I started using WSL to run a Linux shell inside Windows and realized it doesn't come with similar clipboard tools. Not only do they sidestep these problems, but they also make it a breeze to use almost any command-line tool together with the clipboard. From macOS, I'm used to having the convenient pbcopy and pbpaste command-line tools for copying and pasting in the terminal. Don't you hate it when the JSON document copied from the terminal doesn't work because of extra newlines? Or getting a syntax error because the string you pasted into the terminal needs to be escaped?īefore getting a Windows laptop a while ago I primarily used macOS for over a decade. ![]()
0 Comments
Read More
Leave a Reply. |