前幾天朋友問我一個問題,他希望能將 Screen 的 Windows 切換改成單一按鍵即可。用過 Screen 的人就知道,這要求可是一點也不過份。如此每次都用預設的 ctrl + a , + [編號] ,時間久了或切換過於頻繁,我想手指應該也會抽筋!原以為是個簡單的問題,但沒想到中間殺出個程咬金,讓我花了點時間去找對應的資料。
因為他希望是用 F1、F2 … etc (Function Key) 來設定成對應的視窗,我便很直覺的先去翻 Screen Man Page 裡面關於 bindkey 那個段落,看有沒有相關資訊。果不其然,就在那邊和後面的 INPUT TRANSLATION 有關於設定的描述。
Show all of the default key bindings. The application mode entries are marked with [A]. bindkey -k k1 select 1 Make the "F1" key switch to window one.
在 CentOS 的主機上測試沒問題後,原以為問題就這樣輕鬆解決了,沒想到這設定在 FreeBSD 裡,卻沒法正確的被執行。經過一番查找資料後,在 PuTTY 作者的網站裡找到此篇 4.4.3 Changing the action of the function keys and keypad ,裡面的第一個狀況是這樣寫的
In the default mode, labelled ESC [n~, the function keys generate sequences like ESC [11~, ESC [12~ and so on. This matches the general behaviour of Digital's terminals.
經過一試,發現竟然可以在 FreeBSD 下正常運作,但它並沒照說明上寫得 sequences 便可以可運作,經過我直接測試有幾個值是無效且有跳號的問題。發現問題題後,當然就要開始尋找解答。我第一個找到關於 Terminal Term 的文章則是因為太舊,裡面的值根本就是從頭錯到尾。接著我把目標定在 Xterm Control Sequences 的相關資料,希望能在這找到出口,而我也運氣非常好的在 PC-Style Function Keys 那邊找到了它!
根據裡面的資料,實際 12 Function Keys 的值如下表所示:
F1 ~ F5: 11 ~ 15 F6 ~ F10: 17 ~ 21 F11 ~ F12: 23 ~ 24
沒錯!它還真的有跳號。所以 FreeBSD 的使用者要在 Screen 裡用 Function Keys 做熱鍵的話,設定應該是要這樣子才對:
bindkey [11~ [cmd args] # F1 bindkey [12~ [cmd args] # F2 bindkey [13~ [cmd args] # F3 bindkey [14~ [cmd args] # F4 bindkey [15~ [cmd args] # F5 bindkey [17~ [cmd args] # F6 bindkey [18~ [cmd args] # F7 bindkey [19~ [cmd args] # F8 bindkey [20~ [cmd args] # F9 bindkey [21~ [cmd args] # F10 bindkey [23~ [cmd args] # F11 bindkey [24~ [cmd args] # F12
問題到這,可算是順利解決了。不過我自己到是還有個疑惑沒解開,就是為什麼 FreeBSD 和 Linux 得用不同的設定值才能使 Function Keys 正常的運作,但這個問題我想就先擱著,等著過陣子再來找尋問題的答案。
Discussion
No comments for “PuTTY 愛耍人”
Post a comment