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

 COMMAND  PID   USER   FD   TYPE             DEVICE SIZE/OFF   NODE NAME
tmux sinfor cwd DIR , /home/sinfor
tmux sinfor rtd DIR , /
tmux sinfor txt REG , /usr/bin/tmux
tmux sinfor mem REG , /lib/x86_64-linux-gnu/libnss_files-2.19.so
tmux sinfor mem REG , /lib/x86_64-linux-gnu/libnss_nis-2.19.so
tmux sinfor mem REG , /lib/x86_64-linux-gnu/libnsl-2.19.so
tmux sinfor mem REG , /lib/x86_64-linux-gnu/libnss_compat-2.19.so
tmux sinfor mem REG , /lib/x86_64-linux-gnu/libpthread-2.19.so
tmux sinfor mem REG , /lib/x86_64-linux-gnu/libc-2.19.so
tmux sinfor mem REG , /lib/x86_64-linux-gnu/libresolv-2.19.so
tmux sinfor mem REG , /usr/lib/x86_64-linux-gnu/libevent-2.0.so.5.1.
tmux sinfor mem REG , /lib/x86_64-linux-gnu/libtinfo.so.5.9
tmux sinfor mem REG , /lib/x86_64-linux-gnu/libutil-2.19.so
tmux sinfor mem REG , /lib/x86_64-linux-gnu/ld-2.19.so
tmux sinfor 0u CHR , 0t0 /dev/null
tmux sinfor 1u CHR , 0t0 /dev/null
tmux sinfor 2u CHR , 0t0 /dev/null
tmux sinfor 3u unix 0x0000000000000000 0t0 socket
tmux sinfor 4u unix 0x0000000000000000 0t0 socket
tmux sinfor 6u unix 0x0000000000000000 0t0 /tmp/tmux-/default
tmux sinfor 8u CHR , 0t0 /dev/ptmx
tmux sinfor 9u CHR , 0t0 /dev/ptmx
tmux sinfor 10u CHR , 0t0 /dev/ptmx
tmux sinfor 11u CHR , 0t0 /dev/ptmx
tmux sinfor 12u CHR , 0t0 /dev/ptmx
tmux sinfor 13u CHR , 0t0 /dev/ptmx
tmux sinfor 14u CHR , 0t0 /dev/ptmx

lsof -c tmux

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

      -L socket-name
tmux stores the server socket in a directory under /tmp (or TMPDIR if set); the default socket is
named default. This option allows a different socket name to be specified, allowing several inde‐
pendent tmux servers to be run. Unlike -S a full path is not necessary: the sockets are all cre‐
ated in the same directory.
-S socket-path
Specify a full alternative path to the server socket. If -S is specified, the default socket
directory is not used and any -L flag is ignored.

man tmux socket

  仔细分析了一下这里的信息,原来在未指定socket文件(-L)或路径(-S)时,都默认使用了同一个socket,man描述中还提到:

 In tmux, a session is displayed on screen by a client and all sessions are managed by a single server.  The
server and each client are separate processes which communicate through a socket in /tmp.

man tmux socket

  所以,正是因为他们都使用了这个/tmp/tmux-1000/default,导致了指定配置文件对于新开的session无效;

解决方法:  

 alias ts='tmux -f ~/.tmux.conf -L zsh new-session -s'
alias tsb='tmux -f ~/.tmux.conf.bash -L bash new-session -s'
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、mac的bash和zsh如何切换

    1.hostname 192-23-2-2 修改主机名字 2.chsh -s /bin/bash和chsh -s /bin/zsh可以永久切换,也就是一登录进来的就是相应的界面 bash/zsh命令是 ...

  2. Linux之tmux学习

    Linux之tmux学习 前言 在Linux的世界中,命令行是最优雅的交互方式. 但是,只会使用一个交互终端的程序员,是不足以成为Linux下的大牛的. 那么tmux是什么,引用一下原文介绍 tmux ...

  3. shell自动补全功能:bash和zsh

    首要一点:shell有多种,比如bash.zsh.csh.ksh.sh.tcsh等 因此,制作自动补全功能时,要先搞清楚,你使用的是哪种shell,各个shell制作方法是不同的,网上大部分介绍的是关 ...

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

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

  5. Linux下通过受限bash创建指定权限的账号

    在日常业务运维中,有时为了配合解决问题,需要给非运维人员开通系统账号,用于查询日志或代码.通常为了系统安全或避免不必要的误操作等目的,会将账号权限降至最低.下面介绍下在Linux下通过受限bash创建 ...

  6. Mac zsh切换bash bash切换zsh

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

  7. Bash 和 Zsh 开启 vi-mode

    Bash 和 Zsh 开启 vi-mode bash 有两种操作模式,分别是 emacs 和 vi . 在 bash 中 set -o vi # 临时开启 vi 模式 vi ~/.bashrc # 在 ...

  8. zsh切换bash bash切换zsh

    切换bash(需要sudo) chsh -s /bin/bash 切换zsh(不需要sudo) chsh -s /bin/zsh 注意:如果输入命令和密码后提示:no change made. 请加上 ...

  9. bash和zsh切换

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

随机推荐

  1. 基于图的图像分割(Graph-Based Image Segmentation)

    一.介绍 基于图的图像分割(Graph-Based Image Segmentation),论文<Efficient Graph-Based Image Segmentation>,P. ...

  2. Git项目的初始化

    快速设置— 如果你知道该怎么操作,直接使用下面的地址 git@github.com:username/myproject.git 我们强烈建议所有的git仓库都有一个README, LICENSE,  ...

  3. 阿里云centos中mysql的安装及一些常识知识

    -------------------------------------------------------------------    阿里云centos中mysql的安装 工具WinSCP v ...

  4. [leetcode]Max Points on a Line @ Python

    原题地址:https://oj.leetcode.com/problems/max-points-on-a-line/ 题意:Given n points on a 2D plane, find th ...

  5. 用VS自带的打包程序打包Web程序,安装时安装中断

    出现这种问题,可能是你的IIS的兼容性问题: 把IIS兼容性安装好,再试试,应该可以了.

  6. 十个 Laravel 5 程序优化技巧

    性能一直是 Laravel 框架为人诟病的一个点,所以调优 Laravel 程序算是一个必学的技能. 接下来分享一些开发的最佳实践,还有调优技巧,大家有别的建议也欢迎留言讨论. 这里是简单的列表: 配 ...

  7. 【Scala】Scala-循环与遍历

    Scala-循环与遍历 scala for 1000_百度搜索 Scala 2.8的for表达式:性能与运行顺序的改进 - 51CTO.COM scala List集合的用法 - CSDN博客

  8. MySQL数据库select语句的使用方法

    select语句可 以用回车分隔 $sql="select * from article where id=1"和 $sql="select * from article ...

  9. Java-Shiro(一):简介

    简介 Apache Shiro是Java的一个安全权限框架. Shiro可以非常容易的开发出足够好的额应用,其不仅可以用在JavaSE环境,也可以用在Java SE环境. Shiro可以完成:认证.授 ...

  10. Windows系统内存分析工具的介绍

      Windows系统内存分析工具的介绍(进程管理器,资源管理器,性能监视器, VMMap, RamMap,PoolMon) 微软官方提供多种工具来分析Windows 的内存使用情况,除了系统自带的任 ...