Skip to content

Instantly share code, notes, and snippets.

@jacmkno
Last active June 13, 2025 21:42
Show Gist options
  • Save jacmkno/bfaa8a9c0a648e54421987bab1270d9f to your computer and use it in GitHub Desktop.
Save jacmkno/bfaa8a9c0a648e54421987bab1270d9f to your computer and use it in GitHub Desktop.
pcat() {
local module_path="$(pwd)" # Get the current working directory
local allowed_extensions=(
"php" "module" "inc" "install" "profile" "theme" "engine" "py"
"yml" "yaml"
"html.twig" "twig"
"js" "json"
"css" "scss" "sass"
"html"
)
# Check if the path exists and is a directory
if [ ! -d "$module_path" ]; then
echo "Error: Current directory not found or is not a directory: $module_path"
return 1
fi
# Build the regex pattern for extensions
# Escape dots for literal match: \.
# Join extensions with | (OR)
# Handle 'html.twig' explicitly as a full match
local regex_pattern="\.($(IFS='|'; echo "${allowed_extensions[*]//./\\.}"))$"
# Remove 'html.twig' from the main regex and add it as a separate alternative
# This makes sure .html.twig is matched as a whole, not just .twig or .html
regex_pattern="${regex_pattern//\\html\.twig/}" # Remove it first
regex_pattern="${regex_pattern//||/|}" # Clean up any double pipes
regex_pattern="(\.html\.twig|${regex_pattern})" # Add it back as first alternative
# Trim leading/trailing pipes if any after cleanup (e.g., if html.twig was the only one)
regex_pattern="${regex_pattern%|}"
regex_pattern="${regex_pattern#|}"
# Add .* at the beginning to match full filename
regex_pattern=".*${regex_pattern}"
# Construct the find command using -regex
# -regextype egrep for extended regex features (like | for OR)
# -iregex for case-insensitive matching (optional, remove if you need case-sensitivity)
find "$module_path" -type f -regextype egrep -iregex "$regex_pattern" -print0 | \
while IFS= read -r -d $'\0' file; do
# Calculate relative path from the current working directory (module's root)
relative_path="${file#${module_path}/}"
echo ""
echo "--- File: ${relative_path} ---"
cat "${file}"
echo "" # Add a blank line for separation
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment