个人有两份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!

〖Linux〗在tmux同时使用bash和zsh相关推荐

  1. Linux shell:sh csh tcsh ash bash dash zsh

    Shell :贝壳,寓意类似内核的壳,Shell是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内核的服务.Shell 是一个用 C 语言编写的程序,它是用户使用 Linux ...

  2. Linux学习笔记8——bash基本概念

    一个操作系统的组成中,shell是与用户最接近的部分 shell:外壳,也是一种程序 GUI:Gnome,KDE,Xface CLI:sh,csh,ksh,bash,tcsh,zsh Linux中大多 ...

  3. Linux系列6:bash学习

    bash学习 1 认识 BASH 这个 Shell 1.1 硬件.核心与 Shell 1.2 为何要学文字接口的 shell 1.2.1 文字接口的 shell:大家都一样! 1.2.2 远程管理:文 ...

  4. Mac zsh切换bash bash切换zsh

    切换bash    ---->>>chsh -s /bin/bash 切换zsh      ------->>>chsh -s /bin/zsh

  5. linux中bash的功能主要有,Linux系统中的Bash功能的介绍

    今天小编要跟大家分享的文章是关于Linux系统中的Bash功能的介绍.一个完整计算机的体系结构包括:硬件与软件,而软件又分为系统软件与应用软件,负责对硬件仅需管理与操作的是系统软件的内核部分,用户是无 ...

  6. linux命令行使用for循环,小弟我使用过的Linux命令之for - Bash中的For循环

    我使用过的Linux命令之for - Bash中的For循环 我使用过的Linux命令之for - Bash中的For循环 本文链接:http://codingstandards.iteye.com/ ...

  7. Linux编程 3 (初识bash shell与man查看手册)

    一.初识bash shell 1.1 启动 shell   GNU bash shell 能提供对Linux系统的交互式访问.通常是在用户登录终端时启动,登录时系统启动shell依赖于用户账户的配置. ...

  8. linux 变量的继承,solaris移植到linux的大坑:bash和sh中环境变量继承的差异

    问题的引出 项目中脚本A .B,A调用B, 其中A中所有命令均使用绝对路径,B中直接使用 在solaris上工作正常,移植到linux中报错: /syscom/lm/linux//backupgen: ...

  9. Linux脚本开头#!/bin/bash和#!/bin/sh是什么意思以及区别

    Linux脚本开头#!/bin/bash和#!/bin/sh是什么意思以及区别 一.意思 #!/bin/sh是指此脚本使用/bin/sh来解释执行,#!是特殊的表示符,其后面根的是此解释此脚本的she ...

  10. linux shell 安装curl,bash – 不能使用curl安装NPM

    尝试安装NPM时收到此错误.对此错误的任何帮助都非常感激. $ curl http://npmjs.org/install.sh | sh % Total % Received % Xferd Ave ...

最新文章

  1. 旷视推出鼻纹识别,用AI寻找丢失宠物
  2. 2021-09-23对图像深入研究
  3. 06.search_shard_api操作
  4. Linux 命令之 tree -- 以树状图列出目录的内容/查看目录内容
  5. 运用大数据助力大发展
  6. 3-35Pytorch与visdom
  7. boost文件锁的使用
  8. 祥林嫂形容哪类人?祥林嫂比喻什么样的人物?
  9. Input禁用文本框
  10. 页面跳转失效_网站的404页面对于SEO的重要作用
  11. 大哥吾博文写得清清楚楚,怎么就不试一下?
  12. 新手学计算机编程怎么入门 从哪学起
  13. python处理时间序列非平稳_用python做时间序列预测4:平稳/非平稳时间序列
  14. 用计算机弹极乐净土谱,极乐净土计算器乐谱
  15. python爬虫,爬取哔哩哔哩视频
  16. Ochestrator企业数据总线
  17. Linux 基本命令入门
  18. Debian搭建PPTP
  19. 评副高考计算机英语能加分吗,19类人员评副高以下职称时不用再考外语
  20. centos 设置为北京时间

热门文章

  1. 串口命令自动发送_WIFI模块开发教程之W600基础篇3:串口通讯
  2. pandas CSV读取编码问题记录
  3. ueditor php提交表单,ThinkPHP使用Ueditor的方法详解
  4. mysql双节点部署_MariaDB GALERA 集群双节点部署
  5. html标题用什么字母,HTML标题有什么作用?
  6. 都昌信息袁永福:利用电子病历赋能框架,为健康医疗大数据打好基础【电子病历和健康医疗大数据系列】...
  7. 【c++】【多线程】单例模式及其性能
  8. Openssl多个安全补丁简易分析危害及修复方案
  9. Best quotes from The Vampire Diary(《吸血鬼日记》经典台词)
  10. Spring Data JPA整合Redis缓存的配置