在使用tmux時,可能會有幾個煩惱:預設的ctrl b對一些人來說距離好遠不好按,希望能改成其他鍵。或是預設的主題好醜,想要改其他好看的樣式。另外有些人(像我)是效能監視狂,想隨時隨地看目前的系統效能如何,雖然能用top之類的指令來看,但如果能將即時的記憶體、CPU等是使用量秀在session下方的bar欄就好了。本篇就是在解決以上需求。
要個人化很簡單,只要參考這篇把需要的指令放在~/.tmux.conf就好,不過人總是懶的,如果能拿個不錯的設定檔來改就更好了。我個人就是使用tony/tmux-config的來改。這個設定檔讓ctrl a也可以用,並讓樣式好看些,而且也支持tmux-mem-cpu-load。接下來就來介紹如何正確使用此設定檔。
- 安裝需要的套件 (以Ubuntu為例,需要注意版本:cmake>=2.6、g++>=4.6)
$ sudo apt-get install git make cmake g++- 將tony/tmux-config從github上下載下來,並將東西放在~/.tmux內
$ git clone https://github.com/tony/tmux-config.git ~/.tmux- 將他的設定檔連結到你的家目錄下
$ ln -s ~/.tmux/.tmux.conf ~/.tmux.conf- 進入他的資料夾並且將tmux-mem-cpu-load下載下來
$ cd ~/.tmux
$ git submodule init
$ git submodule update- 進到tmux-mem-cpu-load所在的資料夾
$ cd ~/.tmux/vendor/tmux-mem-cpu-load- 用cmake產生Makefile
$ cmake .- 編譯原始檔
$ make- 將tmux-mem-cpu-load安裝到系統
$ sudo make install- 更新tmux的設定 (如果沒有任何session則略過此動作)
$ tmux source-file ~/.tmux.conf- 想看一下修改後的結果,我們來新開一個session
$ tmux就會看到類似下圖的畫面:
應該會很好奇右下角那些數字到底代表什麼意思,根據tmux-mem-cpu-load在github上的描述,那些數字分別代表:
1. 目前記憶體使用量(MB)
2. 可用記憶體大小(MB)
3. CPU使用率(視覺化表示)
4. CPU使用率(數字表示)
5. 過去一分鐘的平均負載
6. 過去五分鐘的平均負載
7. 過去十五'分鐘的平均負載
弄到以上可能還不滿意,畢竟還是別人寫的東西,總不會都是自己想要的,因此在這要改一下他的.tmux.conf以及tmux-mem-cpu-load所顯示的內容。我所改的版本是台灣時間2015/10/9早上10點半從他們github上載下來的,如果他們之後有維護更新的話,可以試著自己改或是用git log及git checkout回到適合的版本(不會的可以參考這個)後,再照著這篇改。
首先編輯~/.tmux/.tmux.conf:
- 個人已經習慣用ctrl b,所以將ctrl a的綁定取消掉
將以下幾行
# Allows us to use C-a a改成to send commands to a TMUX session inside # another TMUX session bind-key a send-prefix
# Allows us to use C-a a以及以下幾行to send commands to a TMUX session inside # another TMUX session #bind-key a send-prefix
# C-b is not acceptable -- Vim uses it set-option -g prefix C-a bind-key C-a last-window改成
# C-b is not acceptable -- Vim uses it #set-option -g prefix C-a #bind-key C-a last-window- 將當前的window標籤改成白底黑字,更清楚知道現在是在哪個window中
將以下幾行
# active window title colors set-window-option -g window-status-current-fg colour166 #orange set-window-option -g window-status-current-bg default #set-window-option -g window-status-attr dim改成
# active window title colors set-window-option -g window-status-current-fg black set-window-option -g window-status-current-bg white #set-window-option -g window-status-attr dim- 改狀態欄的樣式:左方欄只想秀使用者名字其他都不要(最長10個字)、window列表靠左對齊、右方欄不想要有uptime的output
將以下幾行
set -g status-interval 1 set -g status-justify centre # center align window list set -g status-left-length 20 set -g status-right-length 140 set -g status-left '#[fg=green]#H #[fg=black]• #[fg=green,bright]#(uname -r | cut -c 1-6)# [default]' set -g status-right '#[fg=green,bg=default,bright]#(tmux-mem-cpu-load) #[fg=red,dim,bg=def ault]#(uptime | cut -f 4-5 -d " " | cut -f 1 -d ",") #[fg=white,bg=default]%a%l:%M:%S %p#[default] #[fg=blue]%Y-%m-%d'改成
set -g status-interval 1 set -g status-justify left set -g status-left-length 10 set -g status-right-length 140 set -g status-left '#[fg=green,bright]#(whoami)' set -g status-right '#[fg=green,bg=default,bright]#(tmux-mem-cpu-load) #[fg=white,bg=default]%a%l:%M:%S %p#[default] #[fg=blue]%Y-%m-%d'
再來是修改tmux-mem-cpu-load的顯示內容(本文是改Linux的版本,其他OS的版本就自行研究囉!)
- 編輯~/.tmux/vendor/tmux-mem-cpu-load/common/main.cc:取消掉視覺化CPU使用率那格以及平均負載那3格
將以下幾行
std::cout << mem_string( use_colors ) << cpu_string( cpu_usage_delay, graph_lines, use_colors ) << load_string( use_colors );改成
std::cout << mem_string( use_colors ) << cpu_string( cpu_usage_delay, 0, use_colors );- 編輯~/.tmux/vendor/tmux-mem-cpu-load/linux/memory.cc:記憶體使用量單位改成GB,並且用浮點數表示(最多3位數字)
將以下幾行
oss << convert_unit(used_mem, MEGABYTES, KILOBYTES) << '/' << convert_unit(total_mem, MEGABYTES, KILOBYTES) << "MB";改成
oss.precision(3); oss << convert_unit(float(used_mem), GIGABYTES, KILOBYTES) << '/' << convert_unit(float(total_mem), GIGABYTES, KILOBYTES) << "GB";
如果原本有開著session,那這些改變不會立刻看到,必須要重新讀取設定檔才行,輸入以下即可:
$ tmux source-file ~/.tmux.conf(另外如果你原本就已經在某個attached session,那更簡單只要按ctrl b + r他就會幫你重新讀取設定檔囉!)
最後來看一下修改後的成果,應該會出現類似下面的畫面:
沒有留言:
張貼留言