#!/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}"