跳到主要內容

uxterm + tmux 使用心得

公司工作環境主要是一台筆電,一台桌機。筆電因為比較老舊,主要用來看文件查資料,桌機才是用來開發,兩台用 synergy 連接起來,這樣就可以用桌機的鍵盤滑鼠同時控制。為了追蹤自己的工作進度,我利用了 vim-notes 來做條列式的紀錄,底層再加上 git,每個星期 commit 一次,這樣用 git diff 就可以知道自己在某段時間內做了什麼事。

一開始會在筆電開個 terminal 用 mosh 登入桌機來開 vim-notes,工作時邊做紀錄。但是後來遇到一個問題:有時候在筆電看文件的時候想用桌機的 terminal 編輯工作進度。假如要同時用 vim 編輯,就會有同步的問題。為了這個問題找一些遠端同步編輯的程式,後來想想,其實只要同時 attach 到同一個 screen 或 tmux session 就可以兩邊同步操作。

在這之前,只覺得 tmux 就另一個 screen 而已,但是 tmux 有個比 screen 好的地方:當一個 session 有兩個 client 時,tmux 會自動把 window 的大小改成比較小的那個。screen 則是要自己調整。為了這個功能,最後選擇了 tmux + vim-notes 來同步做筆記。

tmux 用慣了以後,又開始覺得是不是可以用 tmux 取代 urxvt 那個有點憋腳的分頁。調校了一下設定,現在主要就用 uxterm + tmux。

目前的設定檔:

.Xresources

UXTerm.termName: xterm-256color

xterm*scrollBar: false
xterm*alternateScroll: true

UXTerm*faceName: Source Code Pro Medium
UXTerm*faceNameDoublesize: Noto Sans Mono CJK TC
UXTerm*faceSize: 12

! Color
UXTerm*foreground: white
UXTerm*background: black

UXTerm*color0: rgb:00/00/00
UXTerm*color8: rgb:55/57/53

UXTerm*color1: rgb:cc/00/00
UXTerm*color9: rgb:ef/29/29

UXTerm*color2rgb:4e/9a/06
UXTerm*color10: rgb:8a/e2/34

UXTerm*color3rgb:c4/a0/00
UXTerm*color11: rgb:fc/e9/4f

UXTerm*color4rgb:34/65/a4
UXTerm*color12: rgb:72/9f/cf

UXTerm*color5rgb:75/50/7b
UXTerm*color13: rgb:ad/7f/a8

UXTerm*color6rgb:06/98/9a
UXTerm*color14: rgb:34/e2/e2

UXTerm*color7rgb:d3/d7/cf
UXTerm*color15: rgb:ee/ee/ec

除了字型跟顏色以外,最重要的是要開啟 alternateScroll,不然滑鼠滾輪在用 less 之類的程式時會是對 uxterm 的 scroll buffer 做操作,而不是捲動 less 的內容。

 .tmux.conf

set -g default-terminal "screen-256color"
set -g history-limit 10000
set -g mouse on

# Scroll in less, vim, etc. (better-mouse-mode)
set -g @emulate-scroll-for-no-mouse-alternate-buffer "on"

# Create/navigate/move the window
bind -n C-S-Down new-window -c "#{pane_current_path}" -a
bind -n C-pgup   prev
bind -n C-pgdn   next
bind -n M-pgup   swap-window -t -1
bind -n M-pgdn   swap-window -t +1
bind    h        split-window -v -c "#{pane_current_path}"
bind    v        split-window -h -c "#{pane_current_path}"


# Based on https://github.com/jimeh/tmux-themepack/blob/master/basic.tmuxtheme
# Basic status bar colors

set -g status-bg black


# Left side of status bar
set -g status-left "#[fg=colour14][#[fg=colour10]#S#[fg=colour14]] #[fg=white]» "

# Window separator
set -g window-status-separator " "

# Window status alignment
set -g status-justify left

# Window status
set -g window-status-bg colour8
set -g window-status-fg colour12
set -g window-status-current-style none
set -g window-status-format " #I#[fg=colour0]:#[fg=colour136]#P:#[fg=colour250]#W#F "

# Current window status
set -g window-status-current-style bold
set -g window-status-current-bg colour19
set -g window-status-current-fg colour11
set -g window-status-current-format " #I:#[fg=colour10]#P:#[fg=white]#W#F "

# Window with activity status
set -g window-status-activity-bg colour9
set -g window-status-activity-fg black

# Right side of status bar
set -g status-right "#[fg=colour14][ #[fg=colour11]#H #[fg=colour14]]"
# Pane border
set -g pane-border-bg default
set -g pane-border-fg colour238

# Active pane border
set -g pane-active-border-bg default
set -g pane-active-border-fg colour7

# Command message
set -g message-command-bg colour3
set -g message-command-fg colour0


# plugins
run-shell ~/.tmux/plugins/tmux-resurrect/resurrect.tmux
run-shell ~/.tmux/plugins/tmux-better-mouse-mode/scroll_copy_mode.tmux


除了改一些自己習慣的按鍵設定,主要就開啟 mouse mode 跟修改 status bar。另外有多加兩個 plugin:resurrectbetter-mouse-mode

resurrect 啟用後會增加兩組快捷鍵:C-b C-s跟 C-b C-r。前者是存下現在全部的 session 狀態,後者則是回復到之前儲存的 session 狀態。這個功能在搭配 vim 的 mksession 之後相當好用,尤其是重開機以後可以很簡單就回復之前的工作狀態。

better-mouse-mode 主要是為了補足 tmux mouse mode 的一些缺點。假如程式本身沒有支援滑鼠滾輪(例如 less),tmux 就會滾動自己的 pane buffer 而不是程式的內容。假如 vim 沒有使用 set mouse=a,也會有這樣的問題。而 better-mouse-mode 則是處理了滑鼠滾輪滾動的事件,個人用起來覺得這樣比較習慣。

雖然說目前還是覺得 mouse mode 有些小問題,像是左鍵選取時不會進到 X 的剪貼簿,中鍵也沒辦法直接貼上。不過這個問題可以在使用時按 shift 解決,所以還算可以接受。

留言

  1. The casino is no longer a'safe' casino - Dr.MCD
    I've never 충주 출장안마 had the 부천 출장마사지 chance to play with my 통영 출장마사지 own 나주 출장안마 family or friends. 광주 출장마사지 They're friends and I have a lot of things to do in the casino and I enjoyed my

    回覆刪除

張貼留言

這個網誌中的熱門文章

Linux Network Scaling: Receiving Packets

Once upon a time, everything was so simple. The network card was slow and had only one queue. When packets arrives, the network card copies packets through DMA and sends an interrupt, and the Linux kernel harvests those packets and completes interrupt processing. As the network cards became faster, the interrupt based model may cause IRQ storm due to the massive incoming packets. This will consume the most of CPU power and freeze the system. To solve this problem, NAPI (interrupt + polling) was proposed. When the kernel receives an interrupt from the network card, it starts to poll the device and harvest packets in the queue as fast as possible. NAPI works nicely with the 1 Gbps network card which is common nowadays. However, it comes to the 10 Gbps, 20 Gbps, or even 40 Gbps network cards, NAPI may not be sufficient. Those cards would demand much faster CPU if we still use one CPU and one queue to receive packets. Fortunately, multi-core CPUs are popular now, so why not process packet

openSUSE/Raspberry Pi 3/Nextcloud 心得

前同事成立 ownCloud 的時候就很好奇是要怎麼用,不過一直到主要開發者另外成立 Nextcloud 都還沒用過,只知道是可以自己架的 file server,也有手機 APP 支援。直到最近家人有備份 iPad 檔案的需求,才想到可以拿被我閒置的 Raspberry Pi 3 來試看看。 其實在這之前就一直在想用什麼方式備份比較好。一開始是買有 USB 的 WiFi router 刷上 openWRT 以後再透過 sftp 拷貝到外接的 USB 硬碟,然後順便架了 DLNA 看照片跟影片。不過 WiFi router 用的晶片運算能力都不太強,用 DLNA 看照片時,有時會因為運算縮圖需要的記憶體太多而整個當掉,算不上是一個好方案。另外只有一顆外接硬碟也不是很保險,所以變成電腦裡面也備份,到後來也吃了不少空間。Google Driver 或 iCloud 之類的除了容量限制,還有綁定服務商的問題,所以還是希望自己家裡架一台。中間有想過買台 NAS,不過一直懶得弄。這次總算有動力來做備份用的 server。 首先是外接硬碟。一開始想用兩顆外接硬碟做 soft raid,但 Raspberry Pi 3 本身供電有限,接兩顆硬碟搞不好推不動,保險起見還是買外接盒。挑了兩三天最後買了 CyberSLIM SSDPRO RAID。優點:體積小(因為是塞兩顆 2.5” 硬碟)、鋁殼無風扇(很安靜)、有硬體 RAID1、支援 USB 3.1。缺點:軔體鳥鳥的(一開始切到 RAID1 還是會認到兩顆硬碟)、LED 燈太亮(晚上關燈在閃的話很刺眼)。因為沒有主動式散熱,所以我搭配了兩顆 HGST  1TB 5400 轉的硬碟,降低散熱需求。另外 Raspberry Pi 3 只有 USB 2.0,所以也不用太在意硬碟效能,加上大部份使用會透過 WiFi,整體效能瓶頸不會是在硬碟這邊。 硬碟設定完,把 openSUSE Leap 42.2 刷進 Raspberry Pi 3 就可以開始裝 Nextcloud 了。安裝難度比想像中低很多,照著 openSUSE wiki 上的步驟做,很容易就可以裝好了。不過呢!因為 server:php:applications 這個 repo 的 build target 沒有 AArch64,所以只能選擇 2.2 的 Insta