1

我不确定以下Rampion 代码的确切用途。它显然应该在光标位置执行命令。

# 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

该命令的目的是什么

4

1 回答 1

2

所以该命令不会运行任意代码。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:: call man,使用从标准输入中读取的任何内容作为命令行参数man
    • || read:: 如果前面的命令返回非零,等待用户回车

从你的输出看起来像

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

    '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在所有模式下将命令绑定到,。
于 2009-07-13T17:53:40.793 回答