博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
〖Linux〗在tmux同时使用bash和zsh
阅读量:7112 次
发布时间:2019-06-28

本文共 4439 字,大约阅读时间需要 14 分钟。

个人有两份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.so10 tmux    3015 sinfor  mem    REG              252,0  1845024 420912 /lib/x86_64-linux-gnu/libc-2.19.so11 tmux    3015 sinfor  mem    REG              252,0   101240 420871 /lib/x86_64-linux-gnu/libresolv-2.19.so12 tmux    3015 sinfor  mem    REG              252,0   276880  13239 /usr/lib/x86_64-linux-gnu/libevent-2.0.so.5.1.913 tmux    3015 sinfor  mem    REG              252,0   167096 398434 /lib/x86_64-linux-gnu/libtinfo.so.5.914 tmux    3015 sinfor  mem    REG              252,0    10680 420938 /lib/x86_64-linux-gnu/libutil-2.19.so15 tmux    3015 sinfor  mem    REG              252,0   149120 420915 /lib/x86_64-linux-gnu/ld-2.19.so16 tmux    3015 sinfor    0u   CHR                1,3      0t0   1052 /dev/null17 tmux    3015 sinfor    1u   CHR                1,3      0t0   1052 /dev/null18 tmux    3015 sinfor    2u   CHR                1,3      0t0   1052 /dev/null19 tmux    3015 sinfor    3u  unix 0x0000000000000000      0t0  18129 socket20 tmux    3015 sinfor    4u  unix 0x0000000000000000      0t0  18130 socket21 tmux    3015 sinfor    6u  unix 0x0000000000000000      0t0  18131 /tmp/tmux-1000/default22 tmux    3015 sinfor    8u   CHR                5,2      0t0   7595 /dev/ptmx23 tmux    3015 sinfor    9u   CHR                5,2      0t0   7595 /dev/ptmx24 tmux    3015 sinfor   10u   CHR                5,2      0t0   7595 /dev/ptmx25 tmux    3015 sinfor   11u   CHR                5,2      0t0   7595 /dev/ptmx26 tmux    3015 sinfor   12u   CHR                5,2      0t0   7595 /dev/ptmx27 tmux    3015 sinfor   13u   CHR                5,2      0t0   7595 /dev/ptmx28 tmux    3015 sinfor   14u   CHR                5,2      0t0   7595 /dev/ptmx
lsof -c tmux

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

1      -L socket-name2                    tmux stores the server socket in a directory under /tmp (or TMPDIR if set); the default socket is3                    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-path7                    Specify a full alternative path to the server socket.  If -S is specified, the default socket8                    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.  The2      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!

转载于:https://www.cnblogs.com/scue/p/4127861.html

你可能感兴趣的文章
LAMP平台部署及应用(二) -- 构建Discuz!论坛服务器
查看>>
反向代理负载均衡模块详述
查看>>
Shell脚本--监控mysql的队列,队列超过300告警
查看>>
HttpClient4.x send request over SSL
查看>>
天益SSL /IPSEC ×××网关设备
查看>>
Ubuntu Server 18.04 通过 nvm 安装 node
查看>>
NSArray数组
查看>>
Apache2.0x 开启gzip压缩
查看>>
关于驰骋表单设计器导入导出问题解决方案
查看>>
利用 XNA 实现 Windows Phone 7 上的电流效果
查看>>
phpcms学习
查看>>
Ubuntu13.10更新源
查看>>
我的友情链接
查看>>
java设计模式-工厂方法模式
查看>>
Java反射机制
查看>>
oVirt 杰云J60使用测试记录
查看>>
【OAuth2学习之路】Spring Security OAuth官网文档翻译
查看>>
Toad for DB2设置
查看>>
关于音视频的一些知识(demux、filter等)
查看>>
[笔记]改善Java程序的151个建议---第一章 Java开发中通用的方法和准则
查看>>