#!/usr/bin/env bash
# -------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/05/07 06:07
# dMod: 2021/05/07 06:07
# Task: Recursively Concatenate Files in the Front Finder Window.
# Tags: @ccstone, @Shell, @Script, @Concatenate, @Files, @Finder, @BBEdit
# -------------------------------------------------------------------------
# Acquire the path to the Front Finder Window. (Finder Insertion Location.)
read -r -d '' asCmdStr <<'EOF'
tell application "Finder"
set targetFolder to insertion location as alias
return POSIX path of targetFolder
end tell
EOF
targetFolderPath=$(osascript -e "$asCmdStr")
# Change the working directory to the Finder Insertion Location.
cd "$targetFolderPath"
# Find files, concatenate their contents, send result to BBEdit.
find -E . -type f \( ! -name ".*" \) -exec sed -n '1,$p' {} \; | bbedit