我的有兩份tmux配置文件:linux
~/.tmux.conf # 使用zsh,主要是平常使用,zsh太好使用了bash
~/.tmux.conf.bash # 使用bash,主要是Android編譯使用session
按照tmux的man手冊,能夠使用 -f config_file 來指定tmux使用的配置文件,因而:socket
alias ta='tmux -f ~/.tmux.conf attach -t' alias tab='tmux -f ~/.tmux.conf.bash -L bash attach -t' alias tl='tmux list-sessions' alias ts='tmux -f ~/.tmux.conf new-session -s' alias tsb='tmux -f ~/.tmux.conf.bash -L bash new-session -s'
可是發現怎麼也不可以同時使用bash和zsh:ide
一旦使用了配置 ~/.tmux.conf 啓動一個session以後,spa
再使用配置文件 ~/.tmux.conf.bash 怎麼也是啓動了zsh,而不是指望的bash;unix
因而再仔細看看tmux使用的文件:code
lsof -c tmuxserver
1 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME 2 tmux 3015 sinfor cwd DIR 252,2 12288 131073 /home/sinfor 3 tmux 3015 sinfor rtd DIR 252,0 4096 2 / 4 tmux 3015 sinfor txt REG 252,0 467144 6935 /usr/bin/tmux 5 tmux 3015 sinfor mem REG 252,0 47712 420929 /lib/x86_64-linux-gnu/libnss_files-2.19.so 6 tmux 3015 sinfor mem REG 252,0 47760 420932 /lib/x86_64-linux-gnu/libnss_nis-2.19.so 7 tmux 3015 sinfor mem REG 252,0 97296 420878 /lib/x86_64-linux-gnu/libnsl-2.19.so 8 tmux 3015 sinfor mem REG 252,0 39824 394969 /lib/x86_64-linux-gnu/libnss_compat-2.19.so 9 tmux 3015 sinfor mem REG 252,0 141574 420941 /lib/x86_64-linux-gnu/libpthread-2.19.so 10 tmux 3015 sinfor mem REG 252,0 1845024 420912 /lib/x86_64-linux-gnu/libc-2.19.so 11 tmux 3015 sinfor mem REG 252,0 101240 420871 /lib/x86_64-linux-gnu/libresolv-2.19.so 12 tmux 3015 sinfor mem REG 252,0 276880 13239 /usr/lib/x86_64-linux-gnu/libevent-2.0.so.5.1.9 13 tmux 3015 sinfor mem REG 252,0 167096 398434 /lib/x86_64-linux-gnu/libtinfo.so.5.9 14 tmux 3015 sinfor mem REG 252,0 10680 420938 /lib/x86_64-linux-gnu/libutil-2.19.so 15 tmux 3015 sinfor mem REG 252,0 149120 420915 /lib/x86_64-linux-gnu/ld-2.19.so 16 tmux 3015 sinfor 0u CHR 1,3 0t0 1052 /dev/null 17 tmux 3015 sinfor 1u CHR 1,3 0t0 1052 /dev/null 18 tmux 3015 sinfor 2u CHR 1,3 0t0 1052 /dev/null 19 tmux 3015 sinfor 3u unix 0x0000000000000000 0t0 18129 socket 20 tmux 3015 sinfor 4u unix 0x0000000000000000 0t0 18130 socket 21 tmux 3015 sinfor 6u unix 0x0000000000000000 0t0 18131 /tmp/tmux-1000/default 22 tmux 3015 sinfor 8u CHR 5,2 0t0 7595 /dev/ptmx 23 tmux 3015 sinfor 9u CHR 5,2 0t0 7595 /dev/ptmx 24 tmux 3015 sinfor 10u CHR 5,2 0t0 7595 /dev/ptmx 25 tmux 3015 sinfor 11u CHR 5,2 0t0 7595 /dev/ptmx 26 tmux 3015 sinfor 12u CHR 5,2 0t0 7595 /dev/ptmx 27 tmux 3015 sinfor 13u CHR 5,2 0t0 7595 /dev/ptmx 28 tmux 3015 sinfor 14u CHR 5,2 0t0 7595 /dev/ptmx
發現/tmp/tmux-1000/default有點蹊蹺,因而再仔細看看man文檔,其中包含socket的描述以下:blog
1 -L socket-name 2 tmux stores the server socket in a directory under /tmp (or TMPDIR if set); the default socket is 3 named default. This option allows a different socket name to be specified, allowing several inde‐ 4 pendent tmux servers to be run. Unlike -S a full path is not necessary: the sockets are all cre‐ 5 ated in the same directory. 6 -S socket-path 7 Specify a full alternative path to the server socket. If -S is specified, the default socket 8 directory is not used and any -L flag is ignored.
仔細分析了一下這裏的信息,原來在未指定socket文件(-L)或路徑(-S)時,都默認使用了同一個socket,man描述中還提到:
1 In tmux, a session is displayed on screen by a client and all sessions are managed by a single server. The 2 server and each client are separate processes which communicate through a socket in /tmp.
因此,正是由於他們都使用了這個/tmp/tmux-1000/default,致使了指定配置文件對於新開的session無效;
解決方法:
1 alias ts='tmux -f ~/.tmux.conf -L zsh new-session -s' 2 alias tsb='tmux -f ~/.tmux.conf.bash -L bash new-session -s' 3 alias tl='tmux -L zsh list-sessions|sed "s/^/[zsh] /g"; tmux -L bash list-sessions|sed "s/^/[bash] /g"'
OK,大功告成,Enjoy!