1
0
Fork 0
mirror of synced 2024-12-13 10:55:46 -05:00

Switching to tab indentation

This commit is contained in:
Bruno Sutic 2014-05-24 23:15:13 +02:00
parent 0e04c1f34f
commit 77747b8e02
5 changed files with 86 additions and 86 deletions

View file

@ -3,20 +3,20 @@
default_tpm_path="$HOME/.tmux/plugins/"
tpm_path_set() {
tmux show-environment -g TMUX_PLUGIN_MANAGER_PATH
tmux show-environment -g TMUX_PLUGIN_MANAGER_PATH
}
set_default_tpm_path() {
tmux set-environment -g TMUX_PLUGIN_MANAGER_PATH "$default_tpm_path"
tmux set-environment -g TMUX_PLUGIN_MANAGER_PATH "$default_tpm_path"
}
ensure_tpm_path() {
if ! tpm_path_set; then
set_default_tpm_path
fi
if ! tpm_path_set; then
set_default_tpm_path
fi
}
main() {
ensure_tpm_path
ensure_tpm_path
}
main

View file

@ -5,27 +5,27 @@ SHARED_TPM_PATH=""
# sets a "global variable" for the current file
shared_set_tpm_path_constant() {
SHARED_TPM_PATH=$(tmux show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)
SHARED_TPM_PATH=$(tmux show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)
}
shared_get_tpm_plugins_list() {
tmux show-option -gqv "$tpm_plugins_variable_name"
tmux show-option -gqv "$tpm_plugins_variable_name"
}
# Allowed plugin name formats:
# 1. "git://github.com/user/plugin_name.git"
# 2. "user/plugin_name"
shared_plugin_name() {
local plugin=$1
# get only the part after the last slash, e.g. "plugin_name.git"
local plugin_basename=$(basename "$plugin")
# remove ".git" extension (if it exists) to get only "plugin_name"
local plugin_name=${plugin_basename%.git}
echo $plugin_name
local plugin=$1
# get only the part after the last slash, e.g. "plugin_name.git"
local plugin_basename=$(basename "$plugin")
# remove ".git" extension (if it exists) to get only "plugin_name"
local plugin_name=${plugin_basename%.git}
echo $plugin_name
}
shared_plugin_path() {
local plugin=$1
local plugin_name=$(shared_plugin_name "$plugin")
echo "$SHARED_TPM_PATH$plugin_name/"
local plugin=$1
local plugin_name=$(shared_plugin_name "$plugin")
echo "$SHARED_TPM_PATH$plugin_name/"
}

View file

@ -8,29 +8,29 @@ source "$CURRENT_DIR/shared_functions.sh"
# Files are ran as executables.
# No errors if the plugin dir does not exist.
silently_source_all_tmux_files() {
local plugin_path=$1
local plugin_tmux_files="$plugin_path*.tmux"
for tmux_file in $plugin_tmux_files; do
# runs *.tmux file as an executable
$tmux_file >/dev/null 2>&1
done
local plugin_path=$1
local plugin_tmux_files="$plugin_path*.tmux"
for tmux_file in $plugin_tmux_files; do
# runs *.tmux file as an executable
$tmux_file >/dev/null 2>&1
done
}
source_plugin() {
local plugin=$1
local plugin_path=$(shared_plugin_path "$plugin")
silently_source_all_tmux_files "$plugin_path"
local plugin=$1
local plugin_path=$(shared_plugin_path "$plugin")
silently_source_all_tmux_files "$plugin_path"
}
source_plugins() {
local plugins=$(shared_get_tpm_plugins_list)
for plugin in $plugins; do
source_plugin "$plugin"
done
local plugins=$(shared_get_tpm_plugins_list)
for plugin in $plugins; do
source_plugin "$plugin"
done
}
main() {
shared_set_tpm_path_constant
source_plugins
shared_set_tpm_path_constant
source_plugins
}
main

View file

@ -7,86 +7,86 @@ 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() {
local message=$1
tmux run-shell "echo '$message'"
local message=$1
tmux run-shell "echo '$message'"
}
end_message() {
display_message ""
display_message "TMUX environment reloaded."
display_message ""
display_message "Done, press ENTER to continue."
display_message ""
display_message "TMUX environment reloaded."
display_message ""
display_message "Done, press ENTER to continue."
}
clone() {
local plugin=$1
cd $SHARED_TPM_PATH &&
git clone --recursive $plugin
local plugin=$1
cd $SHARED_TPM_PATH &&
git clone --recursive $plugin
}
# 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() {
local plugin=$1
clone "$plugin" ||
clone "https://github.com/$plugin"
local plugin=$1
clone "$plugin" ||
clone "https://github.com/$plugin"
}
plugin_already_cloned() {
local plugin=$1
local plugin_path=$(shared_plugin_path "$plugin")
cd $plugin_path &&
git remote
local plugin=$1
local plugin_path=$(shared_plugin_path "$plugin")
cd $plugin_path &&
git remote
}
pull_changes() {
local plugin=$1
local plugin_path=$(shared_plugin_path "$plugin")
cd $plugin_path &&
git pull &&
git submodule update --init --recursive
local plugin=$1
local plugin_path=$(shared_plugin_path "$plugin")
cd $plugin_path &&
git pull &&
git submodule update --init --recursive
}
# pull new changes or clone plugin
sync_plugin() {
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
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
}
sync_plugins() {
local plugins=$(shared_get_tpm_plugins_list)
for plugin in $plugins; do
sync_plugin "$plugin"
done
local plugins=$(shared_get_tpm_plugins_list)
for plugin in $plugins; do
sync_plugin "$plugin"
done
}
ensure_tpm_path_exists() {
mkdir -p $SHARED_TPM_PATH
mkdir -p $SHARED_TPM_PATH
}
reload_tmux_environment() {
tmux source-file ~/.tmux.conf >/dev/null 2>&1
tmux source-file ~/.tmux.conf >/dev/null 2>&1
}
main() {
reload_tmux_environment
shared_set_tpm_path_constant
ensure_tpm_path_exists
sync_plugins
reload_tmux_environment
end_message
reload_tmux_environment
shared_set_tpm_path_constant
ensure_tpm_path_exists
sync_plugins
reload_tmux_environment
end_message
}
main

14
tpm
View file

@ -9,27 +9,27 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Put this in `.tmux.conf` to override the default:
# `set-environment -g TMUX_PLUGIN_MANAGER_PATH "/some/other/path/"`
set_tpm_path() {
$CURRENT_DIR/scripts/set_tpm_path.sh >/dev/null 2>&1
$CURRENT_DIR/scripts/set_tpm_path.sh >/dev/null 2>&1
}
# 1. Fetches plugin names from `@tpm_plugins` user variable.
# 2. Creates full plugin path
# 3. Sources all *.tmux files from each of the plugin directories
# - no errors raised if directory does not exist
# - no errors raised if directory does not exist
# Files are sourced as tmux config files, not as shell scripts!
source_plugins() {
$CURRENT_DIR/scripts/source_plugins.sh >/dev/null 2>&1
$CURRENT_DIR/scripts/source_plugins.sh >/dev/null 2>&1
}
# Defines key binding:
# prefix + I - downloads TPM plugins and reloads TMUX environment.
set_tpm_key_binding() {
$CURRENT_DIR/scripts/key_binding.sh
$CURRENT_DIR/scripts/key_binding.sh
}
main() {
set_tpm_path
set_tpm_key_binding
source_plugins
set_tpm_path
set_tpm_key_binding
source_plugins
}
main