刚使用 homebrew
安装了tmux,现在我正在尝试查找系统范围内的tmux配置文件。man手册显示系统范围内的文件应该位于 /etc/tmux.conf
,但由于某些原因,它并不在那里。默认的 tmux.conf
文件在哪里?
注:当前运行OSX Mavericks操作系统
刚使用 homebrew
安装了tmux,现在我正在尝试查找系统范围内的tmux配置文件。man手册显示系统范围内的文件应该位于 /etc/tmux.conf
,但由于某些原因,它并不在那里。默认的 tmux.conf
文件在哪里?
注:当前运行OSX Mavericks操作系统
/etc/tmux.conf
中添加自己的配置。然而,我会想知道是否有这个必要。我把我的配置放在~/.tmux.conf
中,一切都非常愉快。/usr/local/Cellar/tmux/1.8/etc
目录,但它存放的是Bash完成脚本。我还检查了/usr/local/etc
,发现也没有安装配置文件。默认情况下,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
来自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
创建一个文件,并写入您想要的任何内容。/usr/share/doc/tmux/examples
最近版本的tmux只有示例配置文件,这不是OSX的问题,而是新的默认tmux打包方式。因此,您可以使用其中任何一个,例如:
$cp /usr/share/doc/tmux/examples/someconffile.conf ~/.tmux.conf
/usr/share/doc/tmux/examples
被移动了吗?最近安装后我没有看到它。 - Patrick Dougallls /usr/share/doc
没有显示出tmux
:( - Patrick DougallAlon Gouldman's answer 对我有用。只是想补充一下:
我在使用Ubuntu 20.04时遇到了这个问题。
以下是我解决它的方法:
首先,如果在您的主目录中找不到任何tmux配置文件,则可以使用以下命令在您的主目录(~
)中创建一个:
touch ~/.tmux.conf
~/.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
文件。
就这样了。
希望这有所帮助。
我会试着解决这个问题。以下是我能想到的一些解决方案。虽然我没有运行 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*