我如何才能管道输出的命令到我的剪贴板,并粘贴回来时,使用终端?例如:
cat file | clipboard
我如何才能管道输出的命令到我的剪贴板,并粘贴回来时,使用终端?例如:
cat file | clipboard
当前回答
只是为了覆盖一个边缘情况:),因为问题标题问(至少现在)如何将命令的输出直接复制到剪贴板。
我经常发现,在命令已经执行并且我不想或不能再次执行之后,复制命令的输出是很有用的。
对于这个场景,我们可以使用gdm或类似的鼠标实用程序并使用鼠标进行选择。apt-get安装gdm,然后右键单击或Cntrl+Shift+c和Cntrl+Shift+v组合在终端进行复制和粘贴
Or, which is the preferred method for me (as the mouse cannot select properly inside one pane when you have multiple panes side by side and you need to select more than one line), using tmux we can copy into the tmux buffer using the standard [ , space , move to select , enter or you can select a block of code. Also this is particularly useful when you are inside one of the lanes of the cli multiplexer like tmux AND you need to select a bunch of text, but not the line numbers (my vim setup renders line numbers)
在此之后,您可以使用命令:
tmux save-buffer - | xclip -i
当然,您可以将其命名为您喜欢的名称,或者直接绑定到tmux配置文件中
这只是给您一个概念性的答案,以覆盖这种不可能再次执行命令的边缘情况。如果您需要更具体的代码示例,请告诉我
干杯
其他回答
把这个添加到~/.bashrc:
# Now `cclip' copies and `clipp' pastes'
alias cclip='xclip -selection clipboard'
alias clipp='xclip -selection clipboard -o'
现在剪贴粘贴和剪贴复制-但你也可以做更花哨的东西: 剪切| sed 's/^/ /' |剪辑 ↑缩进您的剪贴板;适用于没有堆栈溢出{}按钮的站点
您可以通过运行以下命令添加它:
printf "\nalias clipp=\'xclip -selection c -o\'\n" >> ~/.bashrc
printf "\nalias cclip=\'xclip -selection c -i\'\n" >> ~/.bashrc
当我需要复制ssh-key时,我通常会执行这个命令:
cat ~/.ssh/id_rsa.pub | pbcopy
Cmd +v或ctrl+v任意位置。
我写了这个小脚本,它把猜测工作从复制/粘贴命令中去掉。
该脚本的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版本依赖于pbcopy和pbpaste,它们已预安装在所有mac电脑上。
#!/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
使用脚本非常简单,因为您只需像这两个示例中所示的那样通过管道输入或输出剪贴板。
$ cat file | clipboard
$ clipboard | less
在不使用外部工具的情况下,如果你连接到服务器视图SSH,这是一个相对简单的命令:
在Windows 7+命令提示符中:
ssh user@server cat /etc/passwd | clip
这将把远程文件的内容放到本地剪贴板中。
(该命令需要运行Pageant以获取密钥,否则它将要求您输入密码。)
在OS X上,使用pbcopy;Pbpaste的方向相反。
pbcopy < .ssh/id_rsa.pub