#!/bin/sh -e
#
# app-extensions - check `CFBundleTypeExtensions` supported by an application

# protect from common misconfiguration to export CDPATH into environment
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH

if [ "$#" -eq 0 ]; then
  printf '%s\n' "$(basename "$0"): [app]"
  exit 1
fi

pathname="${1##*/}"
appname="${pathname%%.*}"
cd "/Applications/${appname}.app/Contents" || exit 1

# grep --after-context=10 CFBundleTypeExtensions Info.plist | grep string
grep -C 10 CFBundleTypeExtensions Info.plist | grep string

# /usr/libexec/PlistBuddy -c "Print :CFBundleDocumentTypes" Info.plist \
#   | grep  "CFBundleTypeExtensions = Array" --after-context 10
# /usr/libexec/PlistBuddy -c "Print :CFBundleDocumentTypes" Info.plist \
#   | grep  "LSItemContentTypes = Array" --after-context 10
