summaryrefslogtreecommitdiff
path: root/scripts/generate_clean_mas_apps.sh
blob: 6bd50f66cc7f2b21042f92c9171956330df00ba5 (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="# This file is generated by scripts/generate_clean_mas_apps.sh\n# Last updated: $(date)\n\n{\n  homebrew.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+="  };\n}"

# echo -e "${output}"

output_file="modules/mac/programs/homebrew/mas-apps.nix"

echo -e "${output}" >"${output_file}"
echo "write to ${output_file}"