mirror of
https://github.com/hydroxycarbamide/dotfiles.git
synced 2025-05-08 13:49:07 -04:00
add tmux
This commit is contained in:
parent
c21063c727
commit
9c06dba63b
236 changed files with 7786 additions and 0 deletions
104
dot_config/tmux/plugins/tpm/scripts/helpers/plugin_functions.sh
Normal file
104
dot_config/tmux/plugins/tpm/scripts/helpers/plugin_functions.sh
Normal file
|
@ -0,0 +1,104 @@
|
|||
# using @tpm_plugins is now deprecated in favor of using @plugin syntax
|
||||
tpm_plugins_variable_name="@tpm_plugins"
|
||||
|
||||
# manually expanding tilde char or `$HOME` variable.
|
||||
_manual_expansion() {
|
||||
local path="$1"
|
||||
local expanded_tilde="${path/#\~/$HOME}"
|
||||
echo "${expanded_tilde/#\$HOME/$HOME}"
|
||||
}
|
||||
|
||||
_tpm_path() {
|
||||
local string_path="$(tmux start-server\; show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/"
|
||||
_manual_expansion "$string_path"
|
||||
}
|
||||
|
||||
_CACHED_TPM_PATH="$(_tpm_path)"
|
||||
|
||||
# Get the absolute path to the users configuration file of TMux.
|
||||
# This includes a prioritized search on different locations.
|
||||
#
|
||||
_get_user_tmux_conf() {
|
||||
# Define the different possible locations.
|
||||
xdg_location="${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf"
|
||||
default_location="$HOME/.tmux.conf"
|
||||
|
||||
# Search for the correct configuration file by priority.
|
||||
if [ -f "$xdg_location" ]; then
|
||||
echo "$xdg_location"
|
||||
|
||||
else
|
||||
echo "$default_location"
|
||||
fi
|
||||
}
|
||||
|
||||
_tmux_conf_contents() {
|
||||
user_config=$(_get_user_tmux_conf)
|
||||
cat /etc/tmux.conf "$user_config" 2>/dev/null
|
||||
if [ "$1" == "full" ]; then # also output content from sourced files
|
||||
local file
|
||||
for file in $(_sourced_files); do
|
||||
cat $(_manual_expansion "$file") 2>/dev/null
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# return files sourced from tmux config files
|
||||
_sourced_files() {
|
||||
_tmux_conf_contents |
|
||||
sed -E -n -e "s/^[[:space:]]*source(-file)?[[:space:]]+(-q+[[:space:]]+)?['\"]?([^'\"]+)['\"]?/\3/p"
|
||||
}
|
||||
|
||||
# Want to be able to abort in certain cases
|
||||
trap "exit 1" TERM
|
||||
export TOP_PID=$$
|
||||
|
||||
_fatal_error_abort() {
|
||||
echo >&2 "Aborting."
|
||||
kill -s TERM $TOP_PID
|
||||
}
|
||||
|
||||
# PUBLIC FUNCTIONS BELOW
|
||||
|
||||
tpm_path() {
|
||||
if [ "$_CACHED_TPM_PATH" == "/" ]; then
|
||||
echo >&2 "FATAL: Tmux Plugin Manager not configured in tmux.conf"
|
||||
_fatal_error_abort
|
||||
fi
|
||||
echo "$_CACHED_TPM_PATH"
|
||||
}
|
||||
|
||||
tpm_plugins_list_helper() {
|
||||
# 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 "full" |
|
||||
awk '/^[ \t]*set(-option)? +-g +@plugin/ { gsub(/'\''/,""); gsub(/'\"'/,""); print $4 }'
|
||||
}
|
||||
|
||||
# Allowed plugin name formats:
|
||||
# 1. "git://github.com/user/plugin_name.git"
|
||||
# 2. "user/plugin_name"
|
||||
plugin_name_helper() {
|
||||
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"
|
||||
}
|
||||
|
||||
plugin_path_helper() {
|
||||
local plugin="$1"
|
||||
local plugin_name="$(plugin_name_helper "$plugin")"
|
||||
echo "$(tpm_path)${plugin_name}/"
|
||||
}
|
||||
|
||||
plugin_already_installed() {
|
||||
local plugin="$1"
|
||||
local plugin_path="$(plugin_path_helper "$plugin")"
|
||||
[ -d "$plugin_path" ] &&
|
||||
cd "$plugin_path" &&
|
||||
git remote >/dev/null 2>&1
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
echo_ok() {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
echo_err() {
|
||||
fail_helper "$*"
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
_has_emacs_mode_keys() {
|
||||
$(tmux show -gw mode-keys | grep -q emacs)
|
||||
}
|
||||
|
||||
tmux_echo() {
|
||||
local message="$1"
|
||||
tmux run-shell "echo '$message'"
|
||||
}
|
||||
|
||||
echo_ok() {
|
||||
tmux_echo "$*"
|
||||
}
|
||||
|
||||
echo_err() {
|
||||
tmux_echo "$*"
|
||||
}
|
||||
|
||||
end_message() {
|
||||
if _has_emacs_mode_keys; then
|
||||
local continue_key="ESCAPE"
|
||||
else
|
||||
local continue_key="ENTER"
|
||||
fi
|
||||
tmux_echo ""
|
||||
tmux_echo "TMUX environment reloaded."
|
||||
tmux_echo ""
|
||||
tmux_echo "Done, press $continue_key to continue."
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
HELPERS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source "$HELPERS_DIR/plugin_functions.sh"
|
||||
|
||||
reload_tmux_environment() {
|
||||
tmux source-file $(_get_user_tmux_conf) >/dev/null 2>&1
|
||||
}
|
17
dot_config/tmux/plugins/tpm/scripts/helpers/utility.sh
Normal file
17
dot_config/tmux/plugins/tpm/scripts/helpers/utility.sh
Normal file
|
@ -0,0 +1,17 @@
|
|||
ensure_tpm_path_exists() {
|
||||
mkdir -p "$(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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue