2009-07-13 91 views
1

我不確定以下Rampion's code的確切用途。 它應該顯然在光標位置執行命令。無法理解.screenrc中的代碼

# 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

什麼命令的目的是什麼?

回答

2

因此,該命令不會運行任意代碼。如果您的光標位於單詞<whatever>的上方,它將在新窗口中運行man <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 ::調用man,使用任何的FROM標準輸入作爲命令行參數讀取man
    • || read ::如果先前的命令返回非零值,等待用戶鍵入回車

從你的輸出,它看起來像

  1. 命令的-c部分沒有得到運行,因爲它看起來像一個新的外殼($是一個提示)。
  2. stuff "^M^D"部分未被正確轉錄。 paste '.'之後的下一個非註釋行應輸入,按鍵的鍵擊,如:

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

如果你有downloaded the file,而不是轉錄,你可能不會有這些問題。

另外,bindkey -m ^fbind f不相同。既不將命令綁定到^g

  • bindkey -m ^f將命令綁定到<CTRL-f>,但僅限於在複製模式下。
  • bind f在所有模式下將命令綁定到<CTRL-A> f
+0

@rampion:謝謝你的回答! – 2009-07-13 19:22:22

+0

你的意思是說,如果你始終在Screen的複製模式下使用命令,你不需要命令'copy'? ---我一直只在屏幕的複製模式下使用這些命令。 *在屏幕的複製模式之外使用這些命令的主要好處是什麼?* --- *你怎麼做到的?* – 2009-07-13 19:32:51

+0

好吧,光標並不總是在複製模式之外的txt結尾。在vim中,當使用readline等時,光標可以指向各種文本。所以我選擇讓我的命令能夠直接在這些情況下工作,而不必先切換到複製模式。 – rampion 2009-07-13 20:14:02