【问题标题】:Unable to understand a code in .screenrc无法理解 .screenrc 中的代码
【发布时间】:2009-07-13 16:59:47
【问题描述】:

我不确定以下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

命令的目的是什么

【问题讨论】:

    标签: gnu-screen


    【解决方案1】:

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

    copy 命令存在的原因是您需要告诉 screen 您要复制某些内容。在路径上时,您可能并不总是处于屏幕的复制模式 - 例如,您可能正在使用 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:: 调用man,使用从标准输入中读取的任何内容作为man 的命令行参数
      • || read :: 如果前面的命令返回非零,等待用户回车

    从你的输出看起来像

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

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

    如果你有downloaded the file,而不是转录它,你可能没有这些问题。

    另外,bindkey -m ^fbind f 不同。也不会将命令绑定到^g

    • bindkey -m ^f 将命令绑定到 &lt;CTRL-f&gt;,但仅限于在复制模式下。
    • bind f 将命令绑定到&lt;CTRL-A&gt; f,在所有模式下。

    【讨论】:

    • @rampion:谢谢你的回答!
    • 你的意思是如果你一直在Screen的复制模式下使用命令,你就不需要命令copy? --- 我一直只在 Screen 的复制模式下使用此类命令。 在 Screen 的复制模式之外使用此类命令的主要好处是什么? --- 您如何做到这一点?
    • 好吧,在复制模式之外,光标并不总是在 txt 的末尾。在 vim 中,当使用 readline 等时,光标可以指向各种文本。所以我选择让我的命令能够在这些情况下直接工作,而不必先切换到复制模式。
    • @rampion:我在stackoverflow.com/questions/1121776/to-understand-xargs-better开了一个关于xargs的新帖子
    • 我需要命令xargs man b/c 我正在通过粘贴输入复制的文本。所以我需要我在新屏幕窗口中运行的命令来等待我粘贴一些文本,而不是在此之前运行。 xargs 等待用户输入,并将其作为我的命令行参数。如果没有 xargs,screen 只会运行 man(没有参数),这不会很有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-05
    • 2011-12-18
    • 2011-08-28
    • 1970-01-01
    相关资源
    最近更新 更多