2011年4月4日 星期一

[Linux] Screen

Screen 是個非常好用的東西
在Linux底下使用shell時,可以利用screen開分頁(你沒聽錯...command line開分頁!!)
也可以將它丟到背景執行,而且就算關掉終端機也還會繼續執行
他的功能很強大,遠及你想像中的強大

是個在文字模式底下相當好用的工具

然而如果只是單單用screen而不改他的設定檔..他的好用功能可能就會很難發揮出來

所以我們往往都會搭配改改設定檔讓screen做出我們想要的效果

設定檔(screenrc)中更可以加入我們想要的熱鍵

範例如下:
# 關閉啟動訊息。
startup_message off

##################################################################
# 加入狀態列。(有多種風格狀態列可以選擇)
##################################################################
#狀態列種類1
caption always "%{=u .r} %-w%<%{=ub .Y}%n %t%{=u .r}%+w "
hardstatus alwaysignore
hardstatus alwayslastline "%{= .K} [%l]%<%=%{= .R}@%H %=%{= .m} %Y/%m/%d%{= .M} %0c "
##################################################################
#種類2
#caption always "%{= wk} %{= KY} [%n]%t @ %H %{-} %= %{= KR} %l %{-} | %{= KG} %Y-%m-%d %{-} "
#hardstatus alwayslastline " %-Lw%{= Bw}%n%f %t%{-}%+Lw %=| %0c:%s "
##################################################################
#種類3
#caption always "%{=u .G} %-w%<%{=ub .y}%n %t%{=u .G}%+w "
#hardstatus alwaysignore
##hardstatus alwayslastline "%{= .K} [%l]%<%=%{= .W}@%H %=%{= .y} %Y/%m/%d%{= .m} %0c:%s "
##################################################################
#種類4
#caption always "%{=u .G} %-w%<%{=ub .y}%n %t%{=u .G}%+w "
#hardstatus alwaysignore
##hardstatus alwayslastline "%{= .K} [%l]%<%=%{= .W}@%H %=%{= .y} %Y/%m/%d%{= .m} %C %A"
##################################################################
#種類5
#caption always "%{=u .G} %-w%<%{=ub .y}%n %t%{=u .G}%+w "
#hardstatus alwayslastline "%{= wk} %{by} %H %{wk} | %-Lw%{kw}◣%{= g}%n%f* %t%{wk}◤%{wk}%+Lw%< %= %{kw}◣%{= R} [%m/%d %c] %{-}"
##################################################################
#種類6
#caption always "%{=u .d} %-w%<%{=ub .B}%n %t%{=u .d}%+w "
#hardstatus alwaysignore 
## hardstatus alwayslastline "%{= .K} [%l]%<%=%{= .W}@%H %=%{= .y} %Y %M %d(%D) %{= .m} %C %A"
##################################################################

#顏色設定#可加可不加
##########################################

term xterm
termcapinfo xterm "Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm"

# allow bold colors - necessary for some reason
attrcolor b ".I"
attrcolor i "+b"

# erase background with current bg color
defbce on
##########################################

# 將預設編碼設為 UTF-8。
defutf8 on

#在編碼為UTF8底下看big5的檔案(Ctrl+a ,b/u)
# C-a b --(switch to)--> view big5 data
bind b encoding big5 utf8
# C-a u --(switch to)--> view utf8 data
bind u encoding utf8 utf8

# 自訂熱鍵
# Ctrl + r : 清理當前視窗(C-a c)
bindkey "^r" clear

# Ctrl + s : 進入複製/捲動模式(C-a esc)
bindkey "^s" copy

# Ctrl + b : 將 screen 丟至背景執行(C-a d)
bindkey "^b" detach

# Ctrl + i : 顯示所有執行中的 screen(C-a *)
bindkey "^i" displays

# Ctrl + d : 關閉當前視窗(C-a k)
bindkey "^d" kill

# Ctrl + l : 將 screen 上鎖(C-a C-x)
bindkey "^l" lockscreen

###########################################################
# Ctrl + 方向鍵的右 : 切換至下個視窗。 (C-a n)
# Ctrl + 方向鍵的左 : 切換至上個視窗。 (C-a p)
# next:下一個 , prev 上一個(依照各個不同的linux 其鍵盤瑪都不同)
#以下的組合可以自行試試哪組可以就用哪組

bindkey "^[O5C" next
bindkey "^[O5D" prev

bindkey "^[[C" next
bindkey "^[[D" prev

bindkey "^[[1;5D" prev
bindkey "^[[1;5C" next

bindkey "^[[5D" prev
bindkey "^[[5C" next
###########################################################

# Ctrl + n : 新增子視窗(C-a c)
bindkey "^n" screen

# Ctrl + f : 切換視窗(C-a Tab)
bindkey "^f" focus

# Ctrl + q : 離開分割視窗(C-a q)
bindkey "^q" only

# Ctrl + k : 關閉當前分割區(C-a X)
bindkey "^k" remove

# Ctrl + o : 水平分割當前視窗(C-a S) 
bindkey "^o" split

# Ctrl + t : 自訂當前視窗標題(C-a A)
bindkey "^t" title

# Ctrl + `/= : 切換子視窗0 ~ 子視窗12。
bindkey "^`" select 0
bindkey "^1" select 1
bindkey "^2" select 2
bindkey "^3" select 3
bindkey "^4" select 4
bindkey "^5" select 5
bindkey "^6" select 6
bindkey "^7" select 7
bindkey "^8" select 8
bindkey "^9" select 9
bindkey "^0" select 10
bindkey "^-" select 11
bindkey "^=" select 12

#不讓某些原本的熱鍵可以再使用
#所以bind掉他
bind s
bind k
bind W
bind ^k
bind .
bind ^\
bind \\
bind ^h
bind h
而顏色部分(如狀態列)

  • %{by} -> b:背景顏色(藍色),y:前景顏色(黃色)
  • 設定背景黑色,前景紅色:${01} or ${kr} or ${0r} or ${k1}
  • 設定 ${br} 後,只想把前景換成黃色:${ y} or ${ 3}
  • 恢復所有顏色的設定:${dd}

支援的顏色有

0 or k     Black
1 or r      Red
2 or g     Green
3 or y     Brown / yellow
4 or b     Blue
5             Purple
6 or c  Cyan
7 or w    White
8             unused/illegal
9             transparent
.              leave color unchanged
d            default color
m           magenta



範例:
1. 設定背景黑色,前景紅色: ${01} or ${kr} or ${0r} or ${k1}
2. 當已設定 ${br} 後,只想把前景換成黃色: ${ y} or ${ 3}
3. 恢復所有顏色的設定: ${dd}
%{=b kr} =b: 加強亮度
另外支援的參數:
b     bold
B     blinking
d     dim
r     reverse
s     standout
u     underline
No related posts.




以下是我用學校nightt主機的畫面(我在裡面裝screen)






 screenrc 的原文範例檔


參考資料:
http://cytseng.twbbs.org/?p=26
http://jonny.ubuntu-tw.net/2011/03/screenrc-of-vimperator-like.html

2 則留言:

  1. 反正就是很強大就對了(妳滾啦

    回覆刪除
  2. 我是覺得很強大啦...
    這就有點像在windows的dos模式底下開分頁一樣...
    真讓人興奮

    回覆刪除