#!/bin/sh -e

# -maxdepth 1 -regex '.+\.app' | rg --replace '$2$1' '^(.*/([^/]+)\.app)/?$' \
app=$(find /Applications /System/Applications /System/Applications/Utilities \
    -maxdepth 1 | rg --replace '$2$1' '^(.*/([^/]+)\.app)/?$' \
  | fzf '--with-nth' 1 '--delimiter' / '--query' "${*:-}" | sed -E 's,[^/]+/,/,')

[ -n "${app}" ] && open "${app}"
