Use the running tmux server to get @plugins or start a new server

I normally start my tmux server with a script because I don't have a
.tmux.config.

i.e.,

    tmux set -g @plugin 'tmux-plugins/tmux-resurrect' \; ...

This change makes it so that @plugins is sourced from the currently
running tmux server instead of spinning up a new one. This also means
that we no longer need to manually parse the configs.

There was also a problem that _tpm_path would not work correctly if
using $XDG_CONFIG_HOME/tmux/tmux.conf because tmux by default doesn't
check that path.

I tested this with both inside and outside tmux by running

    ./tpm/bin/install_plugin
This commit is contained in:
Raul E Rangel 2019-02-20 12:52:58 -07:00
parent 33c5d9a3af
commit 5edba1c1d1
1 changed files with 9 additions and 20 deletions

View File

@ -18,21 +18,13 @@ _get_user_tmux_conf() {
fi
}
_tmux_conf_contents() {
user_config=$(_get_user_tmux_conf)
cat /etc/tmux.conf "$user_config" 2>/dev/null
if [ "$1" == "full" ]; then # also output content from sourced files
local file
for file in $(_sourced_files); do
cat $(_manual_expansion "$file") 2>/dev/null
done
_exec_tmux() {
local OPTS=()
if [[ -z "$TMUX" ]]; then
OPTS+=(-f "$(_get_user_tmux_conf)" start-server \;)
fi
}
# return files sourced from tmux config files
_sourced_files() {
_tmux_conf_contents |
awk '/^[ \t]*source(-file)? +/ { gsub(/'\''/,""); gsub(/'\"'/,""); print $2 }'
tmux "${OPTS[@]}" "${@}"
}
# manually expanding tilde char or `$HOME` variable.
@ -43,7 +35,7 @@ _manual_expansion() {
}
_tpm_path() {
local string_path="$(tmux start-server\; show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/"
local string_path="$(_exec_tmux show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/"
_manual_expansion "$string_path"
}
@ -69,12 +61,9 @@ tpm_path() {
}
tpm_plugins_list_helper() {
# lists plugins from @tpm_plugins option
echo "$(tmux start-server\; show-option -gqv "$tpm_plugins_variable_name")"
# read set -g @plugin "tmux-plugins/tmux-example-plugin" entries
_tmux_conf_contents "full" |
awk '/^[ \t]*set(-option)? +-g +@plugin/ { gsub(/'\''/,""); gsub(/'\"'/,""); print $4 }'
# lists plugins from @tpm_plugins option and @plugins
_exec_tmux show-option -gqv "$tpm_plugins_variable_name" \; \
show-option -gqv "@plugin" \;
}
# Allowed plugin name formats: