• 〖Linux〗在tmux同时使用bash和zsh


    个人有两份tmux配置文件:

      ~/.tmux.conf # 使用zsh,主要是日常使用,zsh太好使用了

      ~/.tmux.conf.bash # 使用bash,主要是Android编译使用

    按照tmux的man手册,可以使用 -f config_file 来指定tmux使用的配置文件,于是:

    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:

      一旦使用了配置 ~/.tmux.conf 启动一个session之后,

      再使用配置文件 ~/.tmux.conf.bash 怎么也是启动了zsh,而不是期望的bash

    于是再仔细看看tmux使用的文件:

      lsof -c tmux

     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
    lsof -c tmux

      发现/tmp/tmux-1000/default有点蹊跷,于是再仔细看看man文档,其中包含socket的描述如下

    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.
    man tmux socket

      仔细分析了一下这里的信息,原来在未指定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.
    man tmux socket

      所以,正是因为他们都使用了这个/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!

  • 相关阅读:
    UVA 1515 Pool construction 最大流跑最小割
    BZOJ 1060: [ZJOI2007]时态同步 树形DP
    Codeforces Round #282 (Div. 1)B. Obsessive String KMP+DP
    BZOJ 4027: [HEOI2015]兔子与樱花 贪心
    BZOJ 2435: [Noi2011]道路修建 dfs搜图
    HDU 5297 Y sequence 容斥/迭代
    HDU 5296 Annoying problem dfs序 lca set
    HDU 5289 Assignment RMQ
    343D/Codeforces Round #200 (Div. 1) D. Water Tree dfs序+数据结构
    php mysqli扩展库之预处理操作
  • 原文地址:https://www.cnblogs.com/scue/p/4127861.html
Copyright © 2020-2023  润新知