tpm/tpm

82 lines
2.4 KiB
Plaintext
Raw Permalink Normal View History

2014-05-18 18:35:55 -04:00
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BINDINGS_DIR="$CURRENT_DIR/bindings"
2015-07-31 17:37:15 -04:00
SCRIPTS_DIR="$CURRENT_DIR/scripts"
2014-05-18 18:35:55 -04:00
2015-07-31 17:37:15 -04:00
source "$SCRIPTS_DIR/variables.sh"
2015-08-03 09:20:40 -04:00
get_tmux_option() {
local option="$1"
local default_value="$2"
local option_value="$(tmux show-option -gqv "$option")"
if [ -z "$option_value" ]; then
echo "$default_value"
else
echo "$option_value"
fi
}
2015-08-02 19:11:39 -04:00
tpm_path_set() {
tmux show-environment -g "$DEFAULT_TPM_ENV_VAR_NAME" >/dev/null 2>&1
}
# Check if configuration file exists at an XDG-compatible location, if so use
# that directory for TMUX_PLUGIN_MANAGER_PATH. Otherwise use $DEFAULT_TPM_PATH.
2015-08-02 19:11:39 -04:00
set_default_tpm_path() {
local xdg_tmux_path="${XDG_CONFIG_HOME:-$HOME/.config}/tmux"
local tpm_path="$DEFAULT_TPM_PATH"
if [ -f "$xdg_tmux_path/tmux.conf" ]; then
tpm_path="$xdg_tmux_path/plugins/"
fi
tmux set-environment -g "$DEFAULT_TPM_ENV_VAR_NAME" "$tpm_path"
2015-08-02 19:11:39 -04:00
}
2014-05-18 18:35:55 -04:00
# Ensures TMUX_PLUGIN_MANAGER_PATH global env variable is set.
#
# Put this in `.tmux.conf` to override the default:
# `set-environment -g TMUX_PLUGIN_MANAGER_PATH "/some/other/path/"`
set_tpm_path() {
2015-08-02 19:11:39 -04:00
if ! tpm_path_set; then
set_default_tpm_path
fi
2014-05-18 18:35:55 -04:00
}
2015-07-06 19:49:33 -04:00
# 1. Fetches plugin names from `@plugin` variables
2014-05-18 18:35:55 -04:00
# 2. Creates full plugin path
# 3. Sources all *.tmux files from each of the plugin directories
2014-05-24 17:15:13 -04:00
# - no errors raised if directory does not exist
2014-05-18 18:35:55 -04:00
# Files are sourced as tmux config files, not as shell scripts!
source_plugins() {
2015-07-31 17:37:15 -04:00
"$SCRIPTS_DIR/source_plugins.sh" >/dev/null 2>&1
2014-05-18 18:35:55 -04:00
}
# prefix + I - downloads TPM plugins and reloads TMUX environment
# prefix + U - updates a plugin (or all of them) and reloads TMUX environment
2015-06-02 15:36:35 -04:00
# prefix + alt + u - remove unused TPM plugins and reloads TMUX environment
set_tpm_key_bindings() {
2015-08-02 18:44:43 -04:00
local install_key="$(get_tmux_option "$install_key_option" "$default_install_key")"
tmux bind-key "$install_key" run-shell "$BINDINGS_DIR/install_plugins"
2015-08-02 18:44:43 -04:00
local update_key="$(get_tmux_option "$update_key_option" "$default_update_key")"
tmux bind-key "$update_key" run-shell "$BINDINGS_DIR/update_plugins"
2015-05-26 23:46:15 -04:00
2015-08-02 18:44:43 -04:00
local clean_key="$(get_tmux_option "$clean_key_option" "$default_clean_key")"
tmux bind-key "$clean_key" run-shell "$BINDINGS_DIR/clean_plugins"
2014-05-18 18:35:55 -04:00
}
supported_tmux_version_ok() {
2015-07-31 17:37:15 -04:00
"$SCRIPTS_DIR/check_tmux_version.sh" "$SUPPORTED_TMUX_VERSION"
}
2014-05-18 18:35:55 -04:00
main() {
if supported_tmux_version_ok; then
set_tpm_path
set_tpm_key_bindings
source_plugins
fi
2014-05-18 18:35:55 -04:00
}
main