-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpms.sh
More file actions
executable file
·148 lines (132 loc) · 4.51 KB
/
pms.sh
File metadata and controls
executable file
·148 lines (132 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env bash
####
# PMS
#
# Main entry point for PMS. Loads libraries, plugins, and themes for the
# requested shell.
#
# Usage:
# PMS=/path/to/pms ./pms.sh bash
#
# Environment Variables:
# PMS Path to the PMS installation directory
# PMS_DEBUG Set to 1 to enable verbose debug output
# PMS_SHELL Target shell to configure (e.g., bash, zsh)
# PMS_PLUGINS Space-separated list of plugins to load
# PMS_THEME Name of the theme to load
####
# shellcheck shell=bash
# Define shells supported by PMS
PMS_SUPPORTED_SHELLS="bash zsh"
# Validate we can properly configure the shell
if [ -z "$1" ]; then
echo
echo "Usage: pms.sh PMS_SHELL"
echo
exit 1
fi
PMS_SHELL="$1"
if [ -z "$PMS" ]; then
echo "The PMS variable is not set. I have no idea what you want me to load."
exit 1
fi
# We want to make sure that ALL the PMS variables are set if the user does not
# set them in one of the env files
# shellcheck source=plugins/pms/env disable=SC1091
source "$PMS/plugins/pms/env"
if [ 1 -eq "${PMS_DEBUG:-0}" ]; then
echo "source $PMS/plugins/pms/env"
fi
# Ensure the requested shell is supported and its environment file exists
case " $PMS_SUPPORTED_SHELLS " in
*" $PMS_SHELL "*) ;;
*)
echo "Unsupported shell: $PMS_SHELL"
exit 1
;;
esac
PMS_SHELL_ENV_FILE="$PMS/plugins/$PMS_SHELL/env"
if [ ! -f "$PMS_SHELL_ENV_FILE" ]; then
echo "Environment file not found: $PMS_SHELL_ENV_FILE"
exit 1
fi
# If the shell has any variables that need to be set, we need to make sure they get set
# shellcheck disable=SC1090
source "$PMS_SHELL_ENV_FILE"
if [ 1 -eq "${PMS_DEBUG:-0}" ]; then
echo "source $PMS_SHELL_ENV_FILE"
fi
####
# Load libraries from the PMS installation followed by any local libraries.
# This includes generic `.sh` files and shell-specific implementations.
# Using `find` avoids shell globbing errors when directories are empty.
#
# @internal
####
# Load core and auxiliary libraries in a stable order. The while loop avoids
# shell-specific word-splitting issues and guarantees each file is sourced
# individually.
while IFS= read -r library_file; do
# shellcheck disable=SC1090
. "$library_file"
if [ 1 -eq "${PMS_DEBUG:-0}" ]; then
echo "source $library_file"
fi
done < <(find "$PMS/lib" -maxdepth 1 -type f \( -name '*.sh' -o -name "*.$PMS_SHELL" \) | sort)
if [ -d "$PMS_LOCAL/lib" ]; then
while IFS= read -r local_library; do
# shellcheck disable=SC1090
. "$local_library"
if [ 1 -eq "${PMS_DEBUG:-0}" ]; then
echo "source $local_library"
fi
done < <(find "$PMS_LOCAL/lib" -maxdepth 1 -type f \( -name '*.sh' -o -name "*.$PMS_SHELL" \) | sort)
fi
_pms_source_file "$HOME/.pms.plugins"
_pms_source_file "$HOME/.pms.theme"
# Load project configuration if present
_pms_project_file_load
# Load the PMS and SHELL plugins
_pms_time "pms" _pms_plugin_load pms
_pms_time "$PMS_SHELL" _pms_plugin_load "$PMS_SHELL"
if [ "${PMS_DEBUG:-0}" -eq 1 ]; then
# If debug is enabled, we want to see the current settings at this point
_pms_message_block "info" "-=[ PMS Settings ]=-"
_pms_message "info" "PMS : $PMS"
_pms_message "info" "PMS_CACHE_DIR : $PMS_CACHE_DIR"
_pms_message "info" "PMS_LOG_DIR : $PMS_LOG_DIR"
_pms_message "info" "PMS_LOCAL : $PMS_LOCAL"
_pms_message "info" "PMS_DEBUG : $PMS_DEBUG"
_pms_message "info" "PMS_REPO : $PMS_REPO"
_pms_message "info" "PMS_REMOTE : $PMS_REMOTE"
_pms_message "info" "PMS_BRANCH : $PMS_BRANCH"
_pms_message "info" "PMS_THEME : $PMS_THEME"
_pms_message "info" "PMS_PLUGINS : ${PMS_PLUGINS[*]}"
_pms_message "info" "PMS_SHELL : $PMS_SHELL"
fi
####
# Load all enabled plugins
####
# Build a normalized list of plugins regardless of string/array definition
plugins_to_load=()
if declare -p PMS_PLUGINS >/dev/null 2>&1 && [ "$(declare -p PMS_PLUGINS 2>/dev/null | awk '{print $2}')" = "-a" ]; then
# PMS_PLUGINS is a bash array
plugins_to_load=("${PMS_PLUGINS[@]}")
else
# PMS_PLUGINS is a string; split on IFS into an array safely
# shellcheck disable=SC2206
read -r -a plugins_to_load <<< "$PMS_PLUGINS"
fi
for plugin in "${plugins_to_load[@]}"; do
if [ "$plugin" != "$PMS_SHELL" ] && [ "$plugin" != "pms" ]; then
_pms_time "$plugin" _pms_plugin_load "$plugin"
fi
done
unset plugin
unset plugins_to_load
####
####
# Load Theme
####
_pms_theme_load "$PMS_THEME"
####