My configuration files for Debian/Ubuntu applications
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

plugin_functions.sh 2.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # using @tpm_plugins is now deprecated in favor of using @plugin syntax
  2. tpm_plugins_variable_name="@tpm_plugins"
  3. # manually expanding tilde char or `$HOME` variable.
  4. _manual_expansion() {
  5. local path="$1"
  6. local expanded_tilde="${path/#\~/$HOME}"
  7. echo "${expanded_tilde/#\$HOME/$HOME}"
  8. }
  9. _tpm_path() {
  10. local string_path="$(tmux start-server\; show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/"
  11. _manual_expansion "$string_path"
  12. }
  13. _CACHED_TPM_PATH="$(_tpm_path)"
  14. # Get the absolute path to the users configuration file of TMux.
  15. # This includes a prioritized search on different locations.
  16. #
  17. _get_user_tmux_conf() {
  18. # Define the different possible locations.
  19. xdg_location="${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf"
  20. default_location="$HOME/.tmux.conf"
  21. # Search for the correct configuration file by priority.
  22. if [ -f "$xdg_location" ]; then
  23. echo "$xdg_location"
  24. else
  25. echo "$default_location"
  26. fi
  27. }
  28. _tmux_conf_contents() {
  29. user_config=$(_get_user_tmux_conf)
  30. cat /etc/tmux.conf "$user_config" 2>/dev/null
  31. if [ "$1" == "full" ]; then # also output content from sourced files
  32. local file
  33. for file in $(_sourced_files); do
  34. cat $(_manual_expansion "$file") 2>/dev/null
  35. done
  36. fi
  37. }
  38. # return files sourced from tmux config files
  39. _sourced_files() {
  40. _tmux_conf_contents |
  41. awk '/^[ \t]*source(-file)? +/ { gsub(/'\''/,""); gsub(/'\"'/,""); print $2 }'
  42. }
  43. # Want to be able to abort in certain cases
  44. trap "exit 1" TERM
  45. export TOP_PID=$$
  46. _fatal_error_abort() {
  47. echo >&2 "Aborting."
  48. kill -s TERM $TOP_PID
  49. }
  50. # PUBLIC FUNCTIONS BELOW
  51. tpm_path() {
  52. if [ "$_CACHED_TPM_PATH" == "/" ]; then
  53. echo >&2 "FATAL: Tmux Plugin Manager not configured in tmux.conf"
  54. _fatal_error_abort
  55. fi
  56. echo "$_CACHED_TPM_PATH"
  57. }
  58. tpm_plugins_list_helper() {
  59. # lists plugins from @tpm_plugins option
  60. echo "$(tmux start-server\; show-option -gqv "$tpm_plugins_variable_name")"
  61. # read set -g @plugin "tmux-plugins/tmux-example-plugin" entries
  62. _tmux_conf_contents "full" |
  63. awk '/^[ \t]*set(-option)? +-g +@plugin/ { gsub(/'\''/,""); gsub(/'\"'/,""); print $4 }'
  64. }
  65. # Allowed plugin name formats:
  66. # 1. "git://github.com/user/plugin_name.git"
  67. # 2. "user/plugin_name"
  68. plugin_name_helper() {
  69. local plugin="$1"
  70. # get only the part after the last slash, e.g. "plugin_name.git"
  71. local plugin_basename="$(basename "$plugin")"
  72. # remove ".git" extension (if it exists) to get only "plugin_name"
  73. local plugin_name="${plugin_basename%.git}"
  74. echo "$plugin_name"
  75. }
  76. plugin_path_helper() {
  77. local plugin="$1"
  78. local plugin_name="$(plugin_name_helper "$plugin")"
  79. echo "$(tpm_path)${plugin_name}/"
  80. }
  81. plugin_already_installed() {
  82. local plugin="$1"
  83. local plugin_path="$(plugin_path_helper "$plugin")"
  84. [ -d "$plugin_path" ] &&
  85. cd "$plugin_path" &&
  86. git remote >/dev/null 2>&1
  87. }