它是可能的管道到/从剪贴板在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
当前回答
pbcopy内置在OS X中:
复制.bash_profile文件的内容:
cat ~/.bash_profile | pbcopy
其他回答
确保使用别名xclip="xclip -selection c" 否则你将无法使用Ctrl+v进行粘贴。
例子: 执行echo -n test | xclip命令后,Ctrl+v将粘贴test
安装
# You can install xclip using `apt-get`
apt-get install xclip
# or `pacman`
pacman -S xclip
# or `dnf`
dnf install xclip
如果你没有apt-get、pacman或dnf,源代码可以在sourceforge上找到。
设置
Bash
在~ /。bash_aliases,添加:
alias setclip="xclip -selection c"
alias getclip="xclip -selection c -o"
不要忘记使用。~ /。Bash_aliases或重新启动配置文件。
Fish
在~ / . config /鱼/配置。鱼,添加:
abbr setclip "xclip -selection c"
abbr getclip "xclip -selection c -o"
不要忘记通过重新启动终端来重新启动fish实例,以便应用更改。
使用
你现在可以使用setclip和getclip,例如:
$ echo foo | setclip
$ getclip
foo
一种从剪贴板粘贴到文件的方法,不需要任何工具,除了echo。
转义你想要粘贴的文本中的单引号:用“\”替换所有出现的“\”并将结果复制到剪贴板。 输入echo -n ' 按Shift +插入 输入' > filename.txt 按回车键
基本上你是这样做的:
Echo -n复制“text”带“\”单引号“\”转义“> filename.txt”
即使复制的文本有新的行,它也能工作。
我只是在我的KDE环境中搜索相同的东西。
请随意使用剪贴和剪贴。
KDE:
> echo "TEST CLIP FROM TERMINAL" | clipcopy
> clippaste
TEST CLIP FROM TERMINAL
这是一个简单的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 |
|| ||
单独运行它只会输出剪贴板中的内容。