Bob Enohp..
43
我写了这个小脚本,从复制/粘贴命令中获取猜测.
Linux版本的脚本依赖于已在系统中安装的xclip.该脚本称为剪贴板.
#!/bin/bash
# Linux version
# Use this script to pipe in/out of the clipboard
#
# Usage: someapp | clipboard # Pipe someapp's output into clipboard
# clipboard | someapp # Pipe clipboard's content into someapp
#
if command -v xclip 1>/dev/null; then
if [[ -p /dev/stdin ]] ; then
# stdin is a pipe
# stdin -> clipboard
xclip -i -selection clipboard
else
# stdin is not a pipe
# clipboard -> stdout
xclip -o -selection clipboard
fi
else
echo "Remember to install xclip"
fi
OS X版本的脚本依赖于所有Mac上预装的pbcopy和pbpaste.
#!/bin/bash
# OS X version
# Use this script to pipe in/out of the clipboard
#
# Usage: someapp | clipboard # Pipe someapp's output into clipboard
# clipboard | someapp # Pipe clipboard's content into someapp
#
if [[ -p /dev/stdin ]] ; then
# stdin is a pipe
# stdin -> clipboard
pbcopy
else
# stdin is not a pipe
# clipboard -> stdout
pbpaste
fi
使用脚本非常简单,因为您只需管道输入或输出,clipboard如这两个示例所示.
$ cat file | clipboard
$ clipboard | less
我在Linux上使用名称`pbcopy`和`pbpaste`,因此它适用于Linux和OS X. (3认同)
您还可以将此脚本包装为函数`clipboard(){...}`并将其粘贴到.bashrc中 (2认同)