-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.sh
More file actions
66 lines (58 loc) · 1.67 KB
/
utils.sh
File metadata and controls
66 lines (58 loc) · 1.67 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
#!/usr/bin/env bash
if [ -n "$BASH_VERSION" ]; then
declare -A TOOL_VERSIONS
elif [ -n "$ZSH_VERSION" ]; then
typeset -A TOOL_VERSIONS
fi
load_tool_versions() {
local base_dir="${HOME}/.dotfiles/mise"
local env_suffix=""
[ -n "$MISE_ENV" ] && env_suffix=".$MISE_ENV"
local os_config_file="${base_dir}/config.${env_suffix}.toml"
local common_config_file="${base_dir}/config.toml"
for file in "$os_config_file" "$common_config_file"; do
[ ! -f "$file" ] && continue
local in_tools=0
while IFS= read -r line; do
if [[ "$line" == "[tools]"* ]]; then
in_tools=1
continue
elif [[ "$line" == "["* ]]; then
in_tools=0
continue
fi
if [ "$in_tools" -eq 1 ]; then
local regex='^([[:alnum:]_-]+)[[:space:]]*=[[:space:]]*"([^"]+)"'
if [ -n "$ZSH_VERSION" ]; then
if [[ "$line" =~ $~regex ]]; then
local tool="${match[1]}"
local version="${match[2]}"
tool="${tool//\"/}"
TOOL_VERSIONS["$tool"]="$version"
fi
elif [ -n "$BASH_VERSION" ]; then
if [[ "$line" =~ $regex ]]; then
local tool="${BASH_REMATCH[1]}"
local version="${BASH_REMATCH[2]}"
TOOL_VERSIONS["$tool"]="$version"
fi
fi
fi
done < "$file"
done
if [ -n "$ZSH_VERSION" ]; then
set -f
for key in ${(k)TOOL_VERSIONS}; do
local newkey="${key//\"/}"
if [ "$newkey" != "$key" ]; then
TOOL_VERSIONS[$newkey]=${TOOL_VERSIONS[$key]}
noglob unset TOOL_VERSIONS[$key]
fi
done
set +f
fi
}
get_tool_version() {
local tool="$1"
echo "${TOOL_VERSIONS[$tool]}"
}