1
0
Fork 0
mirror of synced 2024-11-14 05:28:58 -05:00
tpm/scripts/shared_functions.sh

89 lines
2.2 KiB
Bash
Raw Normal View History

2014-05-18 18:35:55 -04:00
# shared functions and constants
# using @tpm_plugins is now deprecated in favor of using @plugin syntax
2014-05-18 18:35:55 -04:00
tpm_plugins_variable_name="@tpm_plugins"
SHARED_TPM_PATH=""
# sets a "global variable" for the current file
shared_set_tpm_path_constant() {
local string_path="$(tmux start-server\; show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/"
2015-07-07 12:50:55 -04:00
# manually expanding tilde or `$HOME` variable.
string_path="${string_path/#\~/$HOME}"
SHARED_TPM_PATH="${string_path/#\$HOME/$HOME}"
2014-05-18 18:35:55 -04:00
}
_tmux_conf_contents() {
cat /etc/tmux.conf ~/.tmux.conf 2>/dev/null
}
2014-05-18 18:35:55 -04:00
shared_get_tpm_plugins_list() {
# DEPRECATED: 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 |
awk '/^ *set +-g +@plugin/ { gsub(/'\''/,""); gsub(/'\"'/,""); print $4 }'
2014-05-18 18:35:55 -04:00
}
# Allowed plugin name formats:
# 1. "git://github.com/user/plugin_name.git"
# 2. "user/plugin_name"
shared_plugin_name() {
2014-08-05 13:02:42 -04:00
local plugin="$1"
2014-05-24 17:15:13 -04:00
# get only the part after the last slash, e.g. "plugin_name.git"
2014-08-05 13:02:42 -04:00
local plugin_basename="$(basename "$plugin")"
2014-05-24 17:15:13 -04:00
# remove ".git" extension (if it exists) to get only "plugin_name"
2014-08-05 13:02:42 -04:00
local plugin_name="${plugin_basename%.git}"
echo "$plugin_name"
2014-05-18 18:35:55 -04:00
}
shared_plugin_path() {
2015-08-02 19:22:06 -04:00
local plugin="$1"
2015-08-02 18:42:03 -04:00
local plugin_name="$(shared_plugin_name "$plugin")"
echo "${SHARED_TPM_PATH}${plugin_name}/"
2014-05-18 18:35:55 -04:00
}
# TMUX messaging is weird. You only get a nice clean pane if you do it with
# `run-shell` command.
echo_message() {
local message="$1"
tmux run-shell "echo '$message'"
}
reload_tmux_environment() {
tmux source-file ~/.tmux.conf >/dev/null 2>&1
}
plugin_already_installed() {
2014-08-05 13:02:42 -04:00
local plugin="$1"
local plugin_path="$(shared_plugin_path "$plugin")"
[ -d "$plugin_path" ] &&
cd "$plugin_path" &&
git remote >/dev/null 2>&1
}
2014-08-05 13:02:42 -04:00
end_message() {
echo_message ""
echo_message "TMUX environment reloaded."
echo_message ""
echo_message "Done, press ENTER to continue."
}
ensure_tpm_path_exists() {
mkdir -p "$SHARED_TPM_PATH"
}
fail_helper() {
local message="$1"
echo "$message" >&2
FAIL="true"
}
exit_value_helper() {
if [ "$FAIL" == "true" ]; then
exit 1
else
exit 0
fi
}