集成readline的Kill-ring和X11剪贴板 [英] Integrate readline's kill-ring and the X11 clipboard

查看:101
本文介绍了集成readline的Kill-ring和X11剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 .zshrc 中,我使用以下代码片段集成了Shell的剪贴板和我的主要X11剪贴板。由于这种集成,我可以在emacs,firefox和终端之间来回剪切文本,而不必使用鼠标。

In my .zshrc, I use the following snippet to integrate the shell's clipboard and my primary X11 clipboard. Thanks to this integration, I can cut-and-paste text to and from emacs, firefox, and the terminal without having to use the mouse.

kill-line() { zle .kill-line ; echo -n $CUTBUFFER | xclip -i }
zle -N kill-line # bound on C-k

yank() { LBUFFER=$LBUFFER$(xclip -o) }
zle -N yank # bound on C-y

注意:我也在Mac OS X上也使用了这个技巧(使用pbcopy / pbpaste代替并感谢 Synergy ,我的两台计算机共享一个剪贴板。整齐。但这不适用于readline。而且我发现自己经常使用readline,例如在(i)python,gdb,ncftp中……

Note: I use this trick on mac os x as well (with pbcopy/pbpaste instead of xclip) and thanks to Synergy my two computers share a single clipboard. Neat. But it doesn't work with readline. And I find myself using readline quite often, for example in (i)python, in gdb, in ncftp...

所以我的问题来了:是有没有一种方法可以将readline的剪贴板与世界其他地方集成在一起?

当然,我在考虑一些 .inputrc 向导,但欢迎您提供任何见解/想法。

Of course, I'm thinkging about some .inputrc wizardry here, but any insight/ideas would be welcome.

推荐答案

个人而言,我在 GNU屏幕中运行所有内容。这为我提供了所有基于终端的程序的众多功能,而不仅仅是基于readline的程序。它具有自己的粘贴缓冲区,这些缓冲区在当前会话的所有屏幕之间共享,并且可以读取/写入交换文件(可通过 bufferfile 配置)。

Personally, I run everything inside GNU screen. This gives me tons of functionality across all terminal-based programs, not just readline-based ones. It has its own paste buffer(s), which are shared between all screens in your current session, and can read/write an exchange file (configurable with bufferfile).


  • 使用 Ctrl + A [,< 运动>,空格,< 运动> ;;

  • 已复制使用 Enter 粘贴到粘贴缓冲区;

  • 使用 Ctrl + A ] ;

  • 由交换文件的内容替换为 Ctrl + A < ;

  • ,并使用 Ctrl + A > 写出到交换文件中。 / li>
  • A screen selection is made with Ctrl+A, [, <movement>, Space, <movement>;
  • copied to the paste buffer with Enter;
  • pasted with Ctrl+A, ];
  • replaced by the contents of the exchange file with Ctrl+A, <;
  • and written out to the exchange file with Ctrl+A, >.

然后,您所需要的只是帮助您同步 / tmp / screen-exchange 的小帮手和X选择。

Then all you need are little helpers to synchronize /tmp/screen-exchange and the X selection. Something as simple as this would work.

# ~/.screenrc (or entered at C-a : command prompt)
bind '{' exec sh -c 'xclip -o>~/.screen_exchange'
bind '}' exec sh -c 'xclip -i ~/.screen_exchange'

当然,一些更好的绑定和宏会使生活更轻松(这需要 Ca {Ca< Ca] 将X选择粘贴到终端上),但这完全取决于您。

Of course some nicer bindings and macros would make life easier (this requires C-a { C-a < C-a ] to paste X selection to the terminal), but it's completely up to you.

这篇关于集成readline的Kill-ring和X11剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆