blob: b1ea2ab0598b124dd969e392a40d8875bb6a66d3 (
plain) (
blame)
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
|
#!/usr/bin/env bash
if ! command -v mas &>/dev/null; then
echo "error: mas not found"
exit 1
fi
echo "fetching installed apps from app store ..."
apps=$(mas list)
if [[ -z "${apps}" ]]; then
echo "no apps installed from app store"
exit 0
fi
output="masApps = {\n"
while IFS= read -r line; do
app_id=$(echo "${line}" | awk '{print $1}')
app_name=$(echo "${line}" |
cut -d' ' -f2- |
sed -E 's/\([^)]+\)$//' |
sed 's/[[:space:]]+$//' |
sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [[ "${app_name}" =~ [[:space:]] ]]; then
output+=" \"${app_name}\" = ${app_id};\n"
else
output+=" ${app_name} = ${app_id};\n"
fi
done <<<"${apps}"
output+="};"
# echo -e "${output}"
output_file="mas_apps.nix"
echo -e "${output}" >"${output_file}"
echo "write to ${output_file}"
|