2014-05-18 18:35:55 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
|
|
|
source "$CURRENT_DIR/shared_functions.sh"
|
|
|
|
|
|
|
|
# TMUX messaging is weird. You only get a nice clean pane if you do it with
|
|
|
|
# `run-shell` command.
|
|
|
|
display_message() {
|
2014-05-24 17:15:13 -04:00
|
|
|
local message=$1
|
|
|
|
tmux run-shell "echo '$message'"
|
2014-05-18 18:35:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
end_message() {
|
2014-05-24 17:15:13 -04:00
|
|
|
display_message ""
|
|
|
|
display_message "TMUX environment reloaded."
|
|
|
|
display_message ""
|
|
|
|
display_message "Done, press ENTER to continue."
|
2014-05-18 18:35:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
clone() {
|
2014-05-24 17:15:13 -04:00
|
|
|
local plugin=$1
|
|
|
|
cd $SHARED_TPM_PATH &&
|
|
|
|
git clone --recursive $plugin
|
2014-05-18 18:35:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# tries cloning:
|
|
|
|
# 1. plugin name directly - works if it's a valid git url
|
|
|
|
# 2. expands the plugin name to point to a github repo and tries cloning again
|
|
|
|
clone_plugin() {
|
2014-05-24 17:15:13 -04:00
|
|
|
local plugin=$1
|
|
|
|
clone "$plugin" ||
|
|
|
|
clone "https://github.com/$plugin"
|
2014-05-18 18:35:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
plugin_already_cloned() {
|
2014-05-24 17:15:13 -04:00
|
|
|
local plugin=$1
|
|
|
|
local plugin_path=$(shared_plugin_path "$plugin")
|
|
|
|
cd $plugin_path &&
|
|
|
|
git remote
|
2014-05-18 18:35:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pull_changes() {
|
2014-05-24 17:15:13 -04:00
|
|
|
local plugin=$1
|
|
|
|
local plugin_path=$(shared_plugin_path "$plugin")
|
|
|
|
cd $plugin_path &&
|
|
|
|
git pull &&
|
|
|
|
git submodule update --init --recursive
|
2014-05-18 18:35:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# pull new changes or clone plugin
|
|
|
|
sync_plugin() {
|
2014-05-24 17:15:13 -04:00
|
|
|
local plugin=$1
|
|
|
|
if plugin_already_cloned "$plugin"; then
|
|
|
|
# plugin is already cloned - update it
|
|
|
|
display_message "Updating $plugin"
|
|
|
|
pull_changes "$plugin" &&
|
|
|
|
display_message " $plugin update success" ||
|
|
|
|
display_message " $plugin update fail"
|
|
|
|
else
|
|
|
|
# plugin wasn't cloned so far - clone it
|
|
|
|
display_message "Downloading $plugin"
|
|
|
|
clone_plugin "$plugin" &&
|
|
|
|
display_message " $plugin download success" ||
|
|
|
|
display_message " $plugin download fail"
|
|
|
|
fi
|
2014-05-18 18:35:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sync_plugins() {
|
2014-05-24 17:15:13 -04:00
|
|
|
local plugins=$(shared_get_tpm_plugins_list)
|
|
|
|
for plugin in $plugins; do
|
|
|
|
sync_plugin "$plugin"
|
|
|
|
done
|
2014-05-18 18:35:55 -04:00
|
|
|
}
|
|
|
|
|
2014-05-24 09:35:36 -04:00
|
|
|
ensure_tpm_path_exists() {
|
2014-05-24 17:15:13 -04:00
|
|
|
mkdir -p $SHARED_TPM_PATH
|
2014-05-24 09:35:36 -04:00
|
|
|
}
|
|
|
|
|
2014-05-18 18:35:55 -04:00
|
|
|
reload_tmux_environment() {
|
2014-05-24 17:15:13 -04:00
|
|
|
tmux source-file ~/.tmux.conf >/dev/null 2>&1
|
2014-05-18 18:35:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2014-05-24 17:15:13 -04:00
|
|
|
reload_tmux_environment
|
|
|
|
shared_set_tpm_path_constant
|
|
|
|
ensure_tpm_path_exists
|
|
|
|
sync_plugins
|
|
|
|
reload_tmux_environment
|
|
|
|
end_message
|
2014-05-18 18:35:55 -04:00
|
|
|
}
|
|
|
|
main
|