2015-07-06 23:04:26 +00:00
|
|
|
# using @tpm_plugins is now deprecated in favor of using @plugin syntax
|
2014-05-18 22:35:55 +00:00
|
|
|
tpm_plugins_variable_name="@tpm_plugins"
|
|
|
|
|
2015-08-03 16:47:13 +00:00
|
|
|
# manually expanding tilde char or `$HOME` variable.
|
|
|
|
_manual_expansion() {
|
|
|
|
local path="$1"
|
|
|
|
local expanded_tilde="${path/#\~/$HOME}"
|
|
|
|
echo "${expanded_tilde/#\$HOME/$HOME}"
|
|
|
|
}
|
|
|
|
|
2015-08-03 13:29:53 +00:00
|
|
|
_tpm_path() {
|
2015-07-29 21:36:49 +00:00
|
|
|
local string_path="$(tmux start-server\; show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/"
|
2015-08-03 16:47:13 +00:00
|
|
|
_manual_expansion "$string_path"
|
2015-08-03 13:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_CACHED_TPM_PATH="$(_tpm_path)"
|
|
|
|
|
2018-11-02 12:07:53 +00:00
|
|
|
# Get the absolute path to the users configuration file of TMux.
|
|
|
|
# This includes a prioritized search on different locations.
|
|
|
|
#
|
|
|
|
_get_user_tmux_conf() {
|
2018-11-04 10:19:28 +00:00
|
|
|
# Define the different possible locations.
|
2019-07-16 18:58:31 +00:00
|
|
|
xdg_location="${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf"
|
2018-11-04 10:19:28 +00:00
|
|
|
default_location="$HOME/.tmux.conf"
|
2018-11-02 12:07:53 +00:00
|
|
|
|
2018-11-04 10:19:28 +00:00
|
|
|
# Search for the correct configuration file by priority.
|
2018-11-07 08:31:21 +00:00
|
|
|
if [ -f "$xdg_location" ]; then
|
2018-11-04 10:19:28 +00:00
|
|
|
echo "$xdg_location"
|
2018-11-02 12:07:53 +00:00
|
|
|
|
2018-11-04 10:19:28 +00:00
|
|
|
else
|
|
|
|
echo "$default_location"
|
|
|
|
fi
|
2018-11-02 12:07:53 +00:00
|
|
|
}
|
|
|
|
|
2015-07-06 23:04:26 +00:00
|
|
|
_tmux_conf_contents() {
|
2018-11-04 10:19:28 +00:00
|
|
|
user_config=$(_get_user_tmux_conf)
|
2018-11-02 12:07:53 +00:00
|
|
|
cat /etc/tmux.conf "$user_config" 2>/dev/null
|
2015-08-03 16:47:13 +00:00
|
|
|
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
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# return files sourced from tmux config files
|
|
|
|
_sourced_files() {
|
|
|
|
_tmux_conf_contents |
|
2020-02-28 13:08:57 +00:00
|
|
|
sed -E -n -e "s/^[[:space:]]*source(-file)?[[:space:]]+(-q+[[:space:]]+)?['\"]?([^'\"]+)['\"]?/\3/p"
|
2015-08-03 16:47:13 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 03:55:12 +00:00
|
|
|
# Want to be able to abort in certain cases
|
|
|
|
trap "exit 1" TERM
|
|
|
|
export TOP_PID=$$
|
|
|
|
|
|
|
|
_fatal_error_abort() {
|
|
|
|
echo >&2 "Aborting."
|
|
|
|
kill -s TERM $TOP_PID
|
|
|
|
}
|
|
|
|
|
2015-08-03 16:47:13 +00:00
|
|
|
# PUBLIC FUNCTIONS BELOW
|
|
|
|
|
|
|
|
tpm_path() {
|
2016-12-02 03:55:12 +00:00
|
|
|
if [ "$_CACHED_TPM_PATH" == "/" ]; then
|
|
|
|
echo >&2 "FATAL: Tmux Plugin Manager not configured in tmux.conf"
|
|
|
|
_fatal_error_abort
|
|
|
|
fi
|
2015-08-03 16:47:13 +00:00
|
|
|
echo "$_CACHED_TPM_PATH"
|
2015-07-06 23:04:26 +00:00
|
|
|
}
|
|
|
|
|
2015-08-03 15:40:50 +00:00
|
|
|
tpm_plugins_list_helper() {
|
2015-12-14 00:21:47 +00:00
|
|
|
# lists plugins from @tpm_plugins option
|
2015-07-29 21:36:49 +00:00
|
|
|
echo "$(tmux start-server\; show-option -gqv "$tpm_plugins_variable_name")"
|
2015-07-06 23:04:26 +00:00
|
|
|
|
|
|
|
# read set -g @plugin "tmux-plugins/tmux-example-plugin" entries
|
2015-08-03 16:47:13 +00:00
|
|
|
_tmux_conf_contents "full" |
|
2016-02-01 06:41:03 +00:00
|
|
|
awk '/^[ \t]*set(-option)? +-g +@plugin/ { gsub(/'\''/,""); gsub(/'\"'/,""); print $4 }'
|
2014-05-18 22:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Allowed plugin name formats:
|
|
|
|
# 1. "git://github.com/user/plugin_name.git"
|
|
|
|
# 2. "user/plugin_name"
|
2015-08-03 15:40:50 +00:00
|
|
|
plugin_name_helper() {
|
2014-08-05 17:02:42 +00:00
|
|
|
local plugin="$1"
|
2014-05-24 21:15:13 +00:00
|
|
|
# get only the part after the last slash, e.g. "plugin_name.git"
|
2014-08-05 17:02:42 +00:00
|
|
|
local plugin_basename="$(basename "$plugin")"
|
2014-05-24 21:15:13 +00:00
|
|
|
# remove ".git" extension (if it exists) to get only "plugin_name"
|
2014-08-05 17:02:42 +00:00
|
|
|
local plugin_name="${plugin_basename%.git}"
|
|
|
|
echo "$plugin_name"
|
2014-05-18 22:35:55 +00:00
|
|
|
}
|
|
|
|
|
2015-08-03 15:40:50 +00:00
|
|
|
plugin_path_helper() {
|
2015-08-02 23:22:06 +00:00
|
|
|
local plugin="$1"
|
2015-08-03 15:40:50 +00:00
|
|
|
local plugin_name="$(plugin_name_helper "$plugin")"
|
2015-08-03 13:29:53 +00:00
|
|
|
echo "$(tpm_path)${plugin_name}/"
|
2014-05-18 22:35:55 +00:00
|
|
|
}
|
2014-08-05 16:45:59 +00:00
|
|
|
|
|
|
|
plugin_already_installed() {
|
2014-08-05 17:02:42 +00:00
|
|
|
local plugin="$1"
|
2015-08-03 15:40:50 +00:00
|
|
|
local plugin_path="$(plugin_path_helper "$plugin")"
|
2015-07-31 21:23:57 +00:00
|
|
|
[ -d "$plugin_path" ] &&
|
|
|
|
cd "$plugin_path" &&
|
2014-08-05 16:45:59 +00:00
|
|
|
git remote >/dev/null 2>&1
|
|
|
|
}
|