I have been setting up Ubuntu in WSL on windows and I want to set up a pbcopy/pbpaste command for it.
If you are not familiar with these commands, they are very
useful command in Mac OS X terminal.
pbcopy can copy information piped to it to your clipboard. pbpaste can copy information from the
clipboard and pipe it to the next command.
So as can example in Mac OS X you can copy something to the clipboard then run a command like this.
|
> pbcopy > /tmp/file.txt |
Or you can paste into the clipboard
|
> cat file.log | pbpaste |
Now the contents of cat.log is on your local clipboard and you can easily paste it into a documents 😊
So
how can I recreate these commands in Ubuntu 24.04 running as a WSL?
Adding alias
To add the pbpaste and pbcopy commands is as easy as adding a few alias commands in the ~/.profile file.
Open up ~/.profile
|
> vi ~/.profile |
And add the following to it.
|
alias
pbcopy='clip.exe' |
Now restart your terminal or source ~/.profile
|
> source ~/.profile |
Now try it out.
Copy some text to the clipboard and run this command
|
> pbpaste > test.txt |
Then cat it out to prove it worked
|
> cat test.txt |
That worked 😊
Test out pbcopy (copy to the clipboard)
|
> cat ~/.profile | pbcopy |
The paste it into a text editor to prove it worked 😊
No comments:
Post a Comment