我如何才能管道输出的命令到我的剪贴板,并粘贴回来时,使用终端?例如:
cat file | clipboard
我如何才能管道输出的命令到我的剪贴板,并粘贴回来时,使用终端?例如:
cat file | clipboard
当前回答
我使用Parcellite和xsel复制上次提交消息从git到我的剪贴板管理器(由于某种原因xclip不工作):
$ git log -1 --pretty=%B | xsel -i -b
其他回答
我使用Parcellite和xsel复制上次提交消息从git到我的剪贴板管理器(由于某种原因xclip不工作):
$ git log -1 --pretty=%B | xsel -i -b
只是为了覆盖一个边缘情况:),因为问题标题问(至少现在)如何将命令的输出直接复制到剪贴板。
我经常发现,在命令已经执行并且我不想或不能再次执行之后,复制命令的输出是很有用的。
对于这个场景,我们可以使用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配置文件中
这只是给您一个概念性的答案,以覆盖这种不可能再次执行命令的边缘情况。如果您需要更具体的代码示例,请告诉我
干杯
在Wayland上的xcopy似乎不工作,使用wl-clipboard代替。 比如戴着软呢帽
sudo dnf install wl-clipboard
tree | wl-copy
wl-paste > file
把这个添加到~/.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
对于那些使用bash安装在他们的windows系统(称为windows子系统For Linux (WSL))上的用户,尝试xclip将会给出一个错误:
Error: Can't open display: (null)
相反,回想一下linux子系统可以访问windows可执行文件。可以像这样使用clip.exe
echo hello | clip.exe
它允许您使用粘贴命令(ctrl-v)。