它是可能的管道到/从剪贴板在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
当前回答
对于mac,你可以使用这个函数,它使用pbcopy和pbpaste,但更简单:
将此添加到你的.bashrc或.zshrc:
clp() {
if [[ -z "$1" ]]
then
# No input - act as paste
pbpaste;
else
# Input exists - act as copy
echo "$1" | pbcopy;
fi
}
复制使用clp“Content”,粘贴使用clp
其他回答
我只是在我的KDE环境中搜索相同的东西。
请随意使用剪贴和剪贴。
KDE:
> echo "TEST CLIP FROM TERMINAL" | clipcopy
> clippaste
TEST CLIP FROM TERMINAL
这个函数将测试存在哪些剪贴板并使用它。
要验证复制粘贴到你的shell,然后调用函数clippaste:
clippaste () {
if [[ $OSTYPE == darwin* ]]
then
pbpaste
elif [[ $OSTYPE == cygwin* ]]
then
cat /dev/clipboard
else
if command -v xclip &> /dev/null
then
xclip -out -selection clipboard
elif command -v xsel
then
xsel --clipboard --output
else
print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
return 1
fi
fi
}
在macOS系统下,请使用内置的pbcopy和pbpaste命令。
例如,如果你跑步
cat ~/.bashrc | pbcopy
~/的内容。可以使用Cmd + V快捷方式粘贴bashrc文件。
要保存当前剪贴板到一个文件,将输出pbpaste重定向到一个文件:
pbpaste > my_clipboard.txt
在macOS系统中,请使用pbpaste。
例如:
更新剪贴板
pbpaste | ruby -ne ' puts "\|" + $_.split( )[1..4].join("\|") ' | pbcopy
对于mac,你可以使用这个函数,它使用pbcopy和pbpaste,但更简单:
将此添加到你的.bashrc或.zshrc:
clp() {
if [[ -z "$1" ]]
then
# No input - act as paste
pbpaste;
else
# Input exists - act as copy
echo "$1" | pbcopy;
fi
}
复制使用clp“Content”,粘贴使用clp