From 14a1025f52280896ce0adc055932f4622ccd4982 Mon Sep 17 00:00:00 2001 From: 0xmachos <0xmachos@gmail.com> Date: Tue, 23 Apr 2024 16:03:12 +0100 Subject: [PATCH] Add list-apps --- list-apps | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 list-apps diff --git a/list-apps b/list-apps new file mode 100755 index 0000000..1439d1b --- /dev/null +++ b/list-apps @@ -0,0 +1,44 @@ +#!/usr/bin/env zsh +# macos-scripts/list-apps + +# list-apps +# List installed applications +# Explitict goal of not using system_profiler + +set -euo pipefail +# -e exit if any command returns non-zero status code +# -u prevent using undefined variables +# -o pipefail force pipelines to fail on first non-zero status code + +IFS=$'\n\t' +# Set Internal Field Separator to newlines and tabs +# This makes bash consider newlines and tabs as separating words +# See: http://redsymbol.net/articles/unofficial-bash-strict-mode/ + +### UTILITY FUNCTIONS ### +# ctrl_c +# usage + +function ctrl_c { + echo -e "\\n[❌] ${USER} has chosen to quit!" + exit 1 +} + +### END UTILITY FUNCTIONS ### + + +function main { + + trap ctrl_c SIGINT + # Detect and react to the user hitting CTRL + C + + declare -a DIRECTORIES=("/Applications" "$HOME/Applications") + readonly DIRECTORIES + + for directory in "${DIRECTORIES[@]}"; do + find "${directory}" -type d -name "*.app" -depth 1 -exec basename {} .app \; + done + +} + +main "$@"