我如何才能管道输出的命令到我的剪贴板,并粘贴回来时,使用终端?例如:
cat file | clipboard
我如何才能管道输出的命令到我的剪贴板,并粘贴回来时,使用终端?例如:
cat file | clipboard
当前回答
我制作了一个提供类似功能的小工具,但没有使用xclip或xsel。Stdout复制到剪贴板,并可以再次粘贴到终端中。看到的:
https://sourceforge.net/projects/commandlinecopypaste/
注意,这个工具不需要x会话。剪贴板可以在终端内使用,不需要通过Ctrl+V或鼠标中键单击粘贴到其他x窗口中。
其他回答
当我需要复制ssh-key时,我通常会执行这个命令:
cat ~/.ssh/id_rsa.pub | pbcopy
Cmd +v或ctrl+v任意位置。
只是为了覆盖一个边缘情况:),因为问题标题问(至少现在)如何将命令的输出直接复制到剪贴板。
我经常发现,在命令已经执行并且我不想或不能再次执行之后,复制命令的输出是很有用的。
对于这个场景,我们可以使用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配置文件中
这只是给您一个概念性的答案,以覆盖这种不可能再次执行命令的边缘情况。如果您需要更具体的代码示例,请告诉我
干杯
一样:
your_command_which_gives_output | pbcopy
WSL / GNU/Linux(需要xclip包):
your_command_which_gives_output | xclip -sel clip
Git Bash在Windows:
your_command_which_gives_output | clip
我使用Parcellite和xsel复制上次提交消息从git到我的剪贴板管理器(由于某种原因xclip不工作):
$ git log -1 --pretty=%B | xsel -i -b
有一个方法可以在不安装xclip/xsel的情况下工作,如果您没有sudo访问权限,这个方法非常有用。
你只需要安装vimx,这是VIM +剪贴板支持。你可以在大多数发行版中找到它。
将脚本保存为~/copy_to_clipboard.sh,
#!/bin/sh
if [ -z "$1" ]
then
str=" "
else
str=$1
fi
vimx -u NONE -U NONE -N -c "let @a=\".\"" -c "let @*= \"$str\" " -c " put a " -c "sleep 2" -c " q!"
赋予执行权限:chmod +x ~/copy_to_clipboard 并调用它:
~/copy_to_clipboard.sh STRING
出于某种原因,您需要设置一个虚拟的@a寄存器,并将其粘贴到临时文件上。否则剪贴板寄存器将无法正确设置。 最后丢弃临时Vim文件。
你的剪贴板将被设置,你可以用鼠标中点击粘贴它