31
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WSLでpbcopyを使う

Last updated at Posted at 2019-10-24

MacOSではpbcopyのコマンドを使うことで、出力をクリップボードにコピーすることができます。

$ echo hoge | pbcopy

これをWSLで使いたい

WSL上でUbuntuが動いてるので、「Macのpbcopyをubuntuでも使う」で書かれているxselというコマンドを使ってみる

$ sudo apt-get install xsel
$ echo hoge | xsel --clipboard --input
xsel: Can't open display: (null)
: Inappropriate ioctl for device

環境変数でDISPLAYを設定しないとダメっぽい
めんどくさそうので他の方法をとる

Windowsのclip.exeが同じ仕事をしてくれて、WSLで呼び出すことが可能らしいので

$ echo hoge | clip.exe

クリップボードにコピーできました
こっちの方がWSLだとスマートな気がします

最後にエイリアスを定義する

alias pbcopy = 'clip.exe'

参考

31
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?