个人有两份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. .Net Core配置文件读取整理

    一 .配置文件说明 1.配置,主要是 指在程序中使用的一些特殊参数,并且大多数 仅在程序启动的之后指定不需要修改. 2.在以前.Net项目中配置文件主要指app.config或web.config,但 ...

  2. SVG.js 图案使用和use引用

    一.SVG.Pattern 图案设置 var draw = SVG('svg1').size(300, 300); //SVG.Pattern 图案设置 var pattern = draw.patt ...

  3. vmware桥接模式

    vmware桥接模式 桥接网络是指本地物理网卡和虚拟网卡通过VMnet0虚拟交换机进行桥接,物理网卡和虚拟网卡在拓扑图上处于同等地位,那么物理网卡和虚拟网卡就相当于处于同一个网段,虚拟交换机就相当于一 ...

  4. The "Out of socket memory" error

    The "Out of socket memory" error I recently did some work on some of our frontend machines ...

  5. maven与jdk版本不一致报:Unsupported major.minor version 51.0

    I recently uninstalled Java 8, to use Java 6 as I want my code/creations to be usable by more people ...

  6. C# 同一应用程序域不同线程之间的参数传递方式

    很久没有写博客了,最近的项目不用写代码.今天没事就看看thread之间的参数传递方式,这里主要适用于运行在不同线程的两个方法之间参数传递.直接看代码 1.方法之间直接传递参数 void DemoPar ...

  7. HTML中的转义字符 (转)

    HTML中<, >,&等有特殊含义,(前两个字符用于链接签,&用于转义),不能直接使用.使用这三个字符时,应使用它们的转义序列,如下所示: & 或 & &a ...

  8. [leetcode]Gray Code @ Python

    原题地址:https://oj.leetcode.com/problems/gray-code/ 题意: The gray code is a binary numeral system where ...

  9. Kafka:ZK+Kafka+Spark Streaming集群环境搭建(六)针对spark2.2.1以yarn方式启动spark-shell抛出异常:ERROR cluster.YarnSchedulerBackend$YarnSchedulerEndpoint: Sending RequestExecutors(0,0,Map(),Set()) to AM was unsuccessful

    Spark以yarn方式运行时抛出异常: [spark@master bin]$ cd /opt/spark--bin-hadoop2./bin [spark@master bin]$ ./spark ...

  10. wifidog 源码初分析(2)-转

    上一篇分析了接入设备的首次浏览器访问请求如何通过 防火墙过滤规则 重定向到 wifidog 的 HTTP 服务中,本篇主要分析了 wifidog 在接收到 接入设备的 HTTP 访问请求后,如何将此 ...