My configuration files for Debian/Ubuntu applications
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

73 行
2.1 KiB

  1. #!/usr/bin/env bash
  2. CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  3. BINDINGS_DIR="$CURRENT_DIR/bindings"
  4. SCRIPTS_DIR="$CURRENT_DIR/scripts"
  5. source "$SCRIPTS_DIR/variables.sh"
  6. get_tmux_option() {
  7. local option="$1"
  8. local default_value="$2"
  9. local option_value="$(tmux show-option -gqv "$option")"
  10. if [ -z "$option_value" ]; then
  11. echo "$default_value"
  12. else
  13. echo "$option_value"
  14. fi
  15. }
  16. tpm_path_set() {
  17. tmux show-environment -g "$DEFAULT_TPM_ENV_VAR_NAME" >/dev/null 2>&1
  18. }
  19. set_default_tpm_path() {
  20. tmux set-environment -g "$DEFAULT_TPM_ENV_VAR_NAME" "$DEFAULT_TPM_PATH"
  21. }
  22. # Ensures TMUX_PLUGIN_MANAGER_PATH global env variable is set.
  23. #
  24. # Put this in `.tmux.conf` to override the default:
  25. # `set-environment -g TMUX_PLUGIN_MANAGER_PATH "/some/other/path/"`
  26. set_tpm_path() {
  27. if ! tpm_path_set; then
  28. set_default_tpm_path
  29. fi
  30. }
  31. # 1. Fetches plugin names from `@plugin` variables
  32. # 2. Creates full plugin path
  33. # 3. Sources all *.tmux files from each of the plugin directories
  34. # - no errors raised if directory does not exist
  35. # Files are sourced as tmux config files, not as shell scripts!
  36. source_plugins() {
  37. "$SCRIPTS_DIR/source_plugins.sh" >/dev/null 2>&1
  38. }
  39. # prefix + I - downloads TPM plugins and reloads TMUX environment
  40. # prefix + U - updates a plugin (or all of them) and reloads TMUX environment
  41. # prefix + alt + u - remove unused TPM plugins and reloads TMUX environment
  42. set_tpm_key_bindings() {
  43. local install_key="$(get_tmux_option "$install_key_option" "$default_install_key")"
  44. tmux bind-key "$install_key" run-shell "$BINDINGS_DIR/install_plugins"
  45. local update_key="$(get_tmux_option "$update_key_option" "$default_update_key")"
  46. tmux bind-key "$update_key" run-shell "$BINDINGS_DIR/update_plugins"
  47. local clean_key="$(get_tmux_option "$clean_key_option" "$default_clean_key")"
  48. tmux bind-key "$clean_key" run-shell "$BINDINGS_DIR/clean_plugins"
  49. }
  50. supported_tmux_version_ok() {
  51. "$SCRIPTS_DIR/check_tmux_version.sh" "$SUPPORTED_TMUX_VERSION"
  52. }
  53. main() {
  54. if supported_tmux_version_ok; then
  55. set_tpm_path
  56. set_tpm_key_bindings
  57. source_plugins
  58. fi
  59. }
  60. main