Tmux:缺少tmux配置文件?

19

刚使用 homebrew 安装了tmux,现在我正在尝试查找系统范围内的tmux配置文件。man手册显示系统范围内的文件应该位于 /etc/tmux.conf,但由于某些原因,它并不在那里。默认的 tmux.conf 文件在哪里?

注:当前运行OSX Mavericks操作系统

6个回答

19
据我所知,通过Homebrew安装的tmux没有系统范围的配置文件。如果你需要这样一个文件,你可以在/etc/tmux.conf中添加自己的配置。然而,我会想知道是否有这个必要。我把我的配置放在~/.tmux.conf中,一切都非常愉快。
有一个/usr/local/Cellar/tmux/1.8/etc目录,但它存放的是Bash完成脚本。我还检查了/usr/local/etc,发现也没有安装配置文件。
我相信现在tmux通过Homebrew安装程序不会安装自己的系统范围的配置文件,而是将其留给系统管理员来决定是否需要这个功能。

4

默认情况下,tmux没有可编辑的全局配置,它被编译到程序中。

使用以下命令列出编译好的默认值,然后为您的用户创建自己的文件。

tmux list-keys         # show current bindings

tmux show-options -s   # show current server options

tmux show-options -g   # show current global session options
tmux show-options      # show current session options

tmux show-options -gw  # show current global window options
tmux show-options -w   # show current window options

在 tmux 1.7 及以上版本中,show-options 命令可以显示单个选项的值(之前的版本只能列出指定类别的所有选项):

tmux show-options -gw window-status-format

3

来自man tmux页面:

     -f file       Specify an alternative configuration file.  By default, tmux loads the system configuration file from /usr/local/etc/tmux.conf, if present, then looks for a user configuration file at
                   ~/.tmux.conf.

如果没有文件,您可以使用touch ~/.tmux.conf创建一个文件,并写入您想要的任何内容。

问题是关于系统范围的配置文件。 - Sergiu

2
您应该在以下内容中找到有用的东西:
/usr/share/doc/tmux/examples

最近版本的tmux只有示例配置文件,这不是OSX的问题,而是新的默认tmux打包方式。因此,您可以使用其中任何一个,例如:

$cp /usr/share/doc/tmux/examples/someconffile.conf ~/.tmux.conf

那应该就可以了。

1
抱歉,但不应该是“~/.tmux.conf”(缺少点号?) - Biswanath
是的,我的错误,我会编辑我的回答。谢谢你指出来。 - deadPoet
/usr/share/doc/tmux/examples 被移动了吗?最近安装后我没有看到它。 - Patrick Dougall
@PatrickDougall 你是怎么安装tmux的?使用的是哪个操作系统?在Linux上应该是一样的,如果你在OSx上使用Homebrew,那么应该还在。但是如果你使用Macports,那么就会有所不同,因为tmux文件位于/usr/local/Cellar/tmux/xx.version/share/tmux/examples。 - deadPoet
@deadPoet 我在OSX上使用Homebrew,但是ls /usr/share/doc没有显示出tmux :( - Patrick Dougall
没问题,简单的谷歌搜索就可以找到例子 :) - Patrick Dougall

0

Alon Gouldman's answer 对我有用。只是想补充一下:

我在使用Ubuntu 20.04时遇到了这个问题。

以下是我解决它的方法

首先,如果在您的主目录中找不到任何tmux配置文件,则可以使用以下命令在您的主目录~)中创建一个:

touch ~/.tmux.conf

接下来,为了让文件在每次启动 Tmux 会话时都可用,将该文件添加到~/.bash_profile~/.bash_login~/.profile文件中的任一一个。应该将其添加到文件底部:
source "$HOME/.tmux.conf"

这里有一个例子:

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

source "$HOME/.tmux.conf"

注意:文件~/.bash_profile优先级最高,其次是~/.bash_login文件,最后是~/.profile文件。

就这样了。

希望这有所帮助。


你的回答如何回应这个问题? - Sergiu

-1

我会试着解决这个问题。以下是我能想到的一些解决方案。虽然我没有运行 Mac,但我运行 RH、Debian、FreeBSD、Solaris、CYgwin 和其他东西。

根据我从 man tmux中了解到的,-f 标志将指定替代配置文件。默认情况下,tmux/etc/tmux.conf 加载系统配置文件(如果存在),然后在 ~/.tmux.conf 中查找用户配置文件。配置文件是一组 tmux 命令,在服务器第一次启动时按顺序执行。

#!/usr/bin/env bash

unset temporary_array_tmp ; declare -a temporary_array_tmp
temporary_array_tmp=(/etc/tmux.conf ~/.tmux.conf)

# The next line creates an empty global and personal configuration file,
# if it individually does NOT exists.

for i_tmp in "${temporary_array_tmp[@]}" ; do
    [[ ! -f "${i_tmp}" ]] && \
        touch "${i_tmp}" && \
        echo -en "I created an empty tmux configuration file @ ${i_tmp}.  " && \
        echo -e "You need to add configuration settings to ${i_tmp} ." || \
        echo -e "The tmux configuration file ${i_tmp} already exists."
done

# After you add configuration settings, then you need
# to tell tmux to reload the files.

for i_tmp in "${temporary_array_tmp[@]}" ; do
    [[ -f "${i_tmp}" ]] && \
        tmux source-file "${i_tmp}" && \
        echo -e "${i_tmp} The tmux configuration file ${i_tmp} is loaded." || \
        echo -e "The tmux configuration file ${i_tmp} is NOT loaded."
done
unset temporary_array_tmp

值得注意的事项

接下来,您可以使用find查找tmux目录和/或文件。例如:

find ~/ /etc /usr -iname *tmux*

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接