diff options
| -rw-r--r-- | modules/mac/programs/system-packages.nix | 2 | ||||
| -rwxr-xr-x | scripts/generate_clean_mas_apps.sh | 41 |
2 files changed, 43 insertions, 0 deletions
diff --git a/modules/mac/programs/system-packages.nix b/modules/mac/programs/system-packages.nix index bfb352c..25cba16 100644 --- a/modules/mac/programs/system-packages.nix +++ b/modules/mac/programs/system-packages.nix @@ -7,5 +7,7 @@ just flyctl bun + shfmt + shellcheck ]; } diff --git a/scripts/generate_clean_mas_apps.sh b/scripts/generate_clean_mas_apps.sh new file mode 100755 index 0000000..b1ea2ab --- /dev/null +++ b/scripts/generate_clean_mas_apps.sh @@ -0,0 +1,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}" |