我不确定以下内容的确切目的 拉皮恩的代码。它显然应该在光标位置执行命令。

# man-word.screen

# prevent messages from slowing this down
msgminwait 0

# copy word starting at cursor
copy                         # I am not sure why we need this
stuff " e "

# open a new window that waits for a word to run man on
# (and uses 'read' to pause on error)
screen -t man /bin/sh -c 'cat | xargs man || read'       # option -c seems to mean execute

# feed that window the copied word
# be sure to enter '^M' as 'CTRL-V ENTER' and '^D' as 'CTRL-V CTRL-D' (in vim)
paste '.'
# should display as 'stuff "^M^D"'
stuff " "

# turn message waiting back on
msgminwait 1

# vi: ft=screen

该代码绑定在 ^g 这样

bindkey -m ^f source /Users/masi/bin/screen/edit-file-under-cursor.screen

这与

bind f source /Users/masi/bin/screen/edit-file-under-cursor.screen

当光标位于下一行的开头时,我运行代码

vim ~/.zshrc

我得到一个新的缓冲区

替代文本 http://files.getdropbox.com/u/175564/screen-rampion.png

该命令的目的是什么?

有帮助吗?

解决方案

所以该命令不会运行任意代码。它所做的就是运行 man <whatever> 如果您的光标位于该单词上方,则在新屏幕窗口中 <whatever>.

原因是 copy 命令是您需要告诉屏幕您要复制某些内容。在路径上时,您可能并不总是处于屏幕的复制模式 - 例如,您可能正在使用 vim,并将 vim 的光标放在路径上。如果你已经处于复制模式,那么这是一个空操作。

screen -t man /bin/sh -c 'cat | xargs man || read'
  • screen ::打开一个新窗口
  • -t man ::给它一个标题 man
  • /bin/sh -c 'cat | xargs man || read' ::在新窗口中运行此命令,而不是在新窗口中打开默认 shell。
    • /bin/sh ::一个外壳程序
    • -c 'cat | xargs man || read' ::将给定字符串作为脚本运行,而不是以交互模式打开
    • cat | ::等待用户输入(以换行符和 CTRL-D 结尾),然后将其作为用户输入传递给下一个命令
    • xargs man ::称呼 man, ,使用从标准输入读取的任何内容作为命令行参数 man
    • || read ::如果前面的命令返回非零,则等待用户按 Enter 键

从你的输出来看,它看起来像

  1. -c 该命令的一部分没有运行,因为它看起来像一个新的 shell( $ 是一个提示)。
  2. stuff "^M^D" 部分未正确转录。之后的下一个非注释行 paste '.' 应输入,击键为击键,如下所示:

    's', 't', 'u', 'f', 'f', ' ', '"', <CTRL-V>, <ENTER>, <CTRL-V>, <CTRL-D>, '"'
    

如果你有 下载了文件, ,而不是转录它,您可能不会遇到这些问题。

还, bindkey -m ^f 不等于 bind f. 。也不绑定命令 ^g.

  • bindkey -m ^f 将命令绑定到 <CTRL-f>, ,但仅限于复制模式时。
  • bind f 将命令绑定到 <CTRL-A> f, ,在所有模式下。
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top