tpm/scripts/sync_plugins.sh

93 lines
1.9 KiB
Bash
Raw Normal View History

2014-05-18 22:35:55 +00: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.
echo_message() {
2014-05-24 21:15:13 +00:00
local message=$1
tmux run-shell "echo '$message'"
2014-05-18 22:35:55 +00:00
}
end_message() {
echo_message ""
echo_message "TMUX environment reloaded."
echo_message ""
echo_message "Done, press ENTER to continue."
2014-05-18 22:35:55 +00:00
}
clone() {
2014-05-24 21:15:13 +00:00
local plugin=$1
cd $SHARED_TPM_PATH &&
git clone --recursive $plugin
2014-05-18 22:35:55 +00: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 21:15:13 +00:00
local plugin=$1
clone "$plugin" ||
clone "https://github.com/$plugin"
2014-05-18 22:35:55 +00:00
}
plugin_already_cloned() {
2014-05-24 21:15:13 +00:00
local plugin=$1
local plugin_path=$(shared_plugin_path "$plugin")
cd $plugin_path &&
git remote
2014-05-18 22:35:55 +00:00
}
pull_changes() {
2014-05-24 21:15:13 +00:00
local plugin=$1
local plugin_path=$(shared_plugin_path "$plugin")
cd $plugin_path &&
git pull &&
git submodule update --init --recursive
2014-05-18 22:35:55 +00:00
}
# pull new changes or clone plugin
sync_plugin() {
2014-05-24 21:15:13 +00:00
local plugin=$1
if plugin_already_cloned "$plugin"; then
# plugin is already cloned - update it
echo_message "Updating $plugin"
2014-05-24 21:15:13 +00:00
pull_changes "$plugin" &&
echo_message " $plugin update success" ||
echo_message " $plugin update fail"
2014-05-24 21:15:13 +00:00
else
# plugin wasn't cloned so far - clone it
echo_message "Downloading $plugin"
2014-05-24 21:15:13 +00:00
clone_plugin "$plugin" &&
echo_message " $plugin download success" ||
echo_message " $plugin download fail"
2014-05-24 21:15:13 +00:00
fi
2014-05-18 22:35:55 +00:00
}
sync_plugins() {
2014-05-24 21:15:13 +00:00
local plugins=$(shared_get_tpm_plugins_list)
for plugin in $plugins; do
sync_plugin "$plugin"
done
2014-05-18 22:35:55 +00:00
}
ensure_tpm_path_exists() {
2014-05-24 21:15:13 +00:00
mkdir -p $SHARED_TPM_PATH
}
2014-05-18 22:35:55 +00:00
reload_tmux_environment() {
2014-05-24 21:15:13 +00:00
tmux source-file ~/.tmux.conf >/dev/null 2>&1
2014-05-18 22:35:55 +00:00
}
main() {
2014-05-24 21:15:13 +00:00
reload_tmux_environment
shared_set_tpm_path_constant
ensure_tpm_path_exists
sync_plugins
reload_tmux_environment
end_message
2014-05-18 22:35:55 +00:00
}
main