它是可能的管道到/从剪贴板在Bash?
无论是连接到设备手柄还是使用辅助应用程序,我都找不到任何东西。
例如,如果/dev/clip是一个连接到剪贴板的设备,我们可以这样做:
cat /dev/clip # Dump the contents of the clipboard
cat foo > /dev/clip # Dump the contents of "foo" into the clipboard
它是可能的管道到/从剪贴板在Bash?
无论是连接到设备手柄还是使用辅助应用程序,我都找不到任何东西。
例如,如果/dev/clip是一个连接到剪贴板的设备,我们可以这样做:
cat /dev/clip # Dump the contents of the clipboard
cat foo > /dev/clip # Dump the contents of "foo" into the clipboard
当前回答
xsel在Debian/Ubuntu/Mint
# append to clipboard:
cat 'the file with content' | xsel -ab
# or type in the happy face :) and ...
echo 'the happy face :) and content' | xsel -ib
# show clipboard
xsel -ob
# Get more info:
man xsel
安装
sudo apt-get install xsel
其他回答
Try
xclip
xclip - command line interface to X selections (clipboard)
man
在Wayland上,xcopy似乎不能工作。使用wl-clipboard代替。
例如,在Fedora上:
sudo dnf install wl-clipboard
tree | wl-copy
wl-paste > file
几年前我写的几个Windows程序。它们允许您转储,推送,追加和打印剪贴板。它是这样工作的:
dumpclip | perl -pe "s/monkey/chimp/g;" | pushclip
它包括源代码:cmd_clip.zip
pbcopy内置在OS X中:
复制.bash_profile文件的内容:
cat ~/.bash_profile | pbcopy
这是一个简单的Python脚本,可以满足你的需要:
#!/usr/bin/python
import sys
# Clipboard storage
clipboard_file = '/tmp/clipboard.tmp'
if(sys.stdin.isatty()): # Should write clipboard contents out to stdout
with open(clipboard_file, 'r') as c:
sys.stdout.write(c.read())
elif(sys.stdout.isatty()): # Should save stdin to clipboard
with open(clipboard_file, 'w') as c:
c.write(sys.stdin.read())
将其保存为路径中的可执行文件(我将其保存到/usr/local/bin/clip.)你可以输入要保存到剪贴板上的内容。
echo "Hello World" | clip
你可以将剪贴板中的内容传输到其他程序……
clip | cowsay
_____________
< Hello World >
-------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
单独运行它只会输出剪贴板中的内容。