Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for variable expansion in config files #233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

a24k
Copy link

@a24k a24k commented Oct 28, 2022

If tmux.conf refers other file by source-file command that uses variable, it'll be better to expand variables into actual values.

Background

In XDG style directory, I'd like to use tmux.conf with variables like following example.

# tmux.conf ------------------------------------------------

TMUX_CONF_PATH="~/.config/tmux"

source "${TMUX_CONF_PATH}/general.conf"
source "${TMUX_CONF_PATH}/plugins.conf"
source "${TMUX_CONF_PATH}/pane.conf"
source "${TMUX_CONF_PATH}/status.conf"


# plugins.conf ---------------------------------------------

TMUX_PLUGIN_MANAGER_PATH="~/.local/share/tmux/plugins"

set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

run "${TMUX_PLUGIN_MANAGER_PATH}/tpm/tpm"

It works well about tmux configurations, but tpm can't read @plugin entries from plugins.conf.

Current version of tpm expands ~ to $HOME with _manual_expansion() function, but never expands variables.

Solution

In _sourced_files() function, tpm extract parameter of source-file commands from tmux.conf.

We can put these parameters into echo command and process with bash, then get filenames with parameters expanded. Both single and double quotation marks are must be recognized correctly.

# intermediate script, to be processed with bash

echo "${TMUX_CONF_PATH}/general.conf"
echo "${TMUX_CONF_PATH}/plugins.conf"
echo "${TMUX_CONF_PATH}/pane.conf"
echo "${TMUX_CONF_PATH}/status.conf"

If tmux.conf refers other file by source-file command that uses variable,
it'll be better to expand variables into actual values.

Both single and double quotation marks are must be recognized correctly.
@FranklinYu
Copy link
Contributor

Shameless plug: #85 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants