无法理解.screenrc中的代码

时间:2009-07-13 16:59:47

标签: gnu-screen

我不确定以下Rampion's code的确切目的。 它应该显然在光标位置执行命令。

# 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

我得到一个新的缓冲区

alt text http://files.getdropbox.com/u/175564/screen-rampion.png

该命令的目的是什么?

1 个答案:

答案 0 :(得分: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 ::一个shell程序
    • -c 'cat | xargs man || read' ::将给定的字符串作为脚本运行,而不是以交互模式打开
    • cat | ::等待用户输入(以换行符和CTRL-D结尾),然后将其作为用户输入传递给下一个命令
    • xargs man :: call man,使用从标准输入读取的任何内容作为man的命令行参数
    • || read ::如果先前的命令返回非零,则等待用户按Enter

从您的输出看起来像

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

    's', 't', 'u', 'f', 'f', ' ', '"', <CTRL-V>, <ENTER>, <CTRL-V>, <CTRL-D>, '"'
    
  3. 如果您有downloaded the file,而不是转录它,则可能没有这些问题。

    此外,bindkey -m ^fbind f不同。并且都没有将命令绑定到^g

    • bindkey -m ^f将命令绑定到<CTRL-f>,但仅限于处于复制模式时。
    • bind f在所有模式下将命令绑定到<CTRL-A> f