-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
|
||
# Function to print file content with the format | ||
print_file_content() { | ||
local filepath=$1 | ||
echo "$filepath:" | ||
cat "$filepath" | ||
echo -e "\n" | ||
} | ||
|
||
# Function to collect file content | ||
collect_file_content() { | ||
local filepath=$1 | ||
echo "$filepath:" | ||
cat "$filepath" | ||
echo -e "\n" | ||
} | ||
|
||
# Function to copy combined content to clipboard | ||
copy_combined_content_to_clipboard() { | ||
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
# macOS | ||
echo "$combined_content" | pbcopy | ||
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
# Linux | ||
echo "$combined_content" | xclip -selection clipboard | ||
else | ||
echo "Clipboard copy not supported on this OS." | ||
exit 1 | ||
fi | ||
} | ||
|
||
# List of file extensions to include | ||
include_extensions=("py" "yml" "toml" "md" "txt" "Dockerfile") | ||
|
||
# Parse command line options | ||
print_content=true | ||
copy_content=false | ||
while getopts "nc" opt; do | ||
case $opt in | ||
n) | ||
print_content=false | ||
;; | ||
c) | ||
copy_content=true | ||
;; | ||
*) | ||
echo "Usage: $0 [-n] [-c]" | ||
echo " -n Print only file names" | ||
echo " -c Copy combined content to clipboard" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# Initialize combined content variable | ||
combined_content="" | ||
|
||
# Iterate through each file in the directory structure | ||
for filepath in $(find . -type f); do | ||
filename=$(basename -- "$filepath") | ||
extension="${filename##*.}" | ||
|
||
# Check if the file has an extension or is a Dockerfile | ||
if [[ " ${include_extensions[@]} " =~ " ${extension} " ]] || [[ "$filename" == "Dockerfile" ]]; then | ||
echo "$filepath" | ||
if $print_content; then | ||
print_file_content "$filepath" | ||
fi | ||
if $copy_content; then | ||
combined_content+=$(collect_file_content "$filepath") | ||
fi | ||
fi | ||
done | ||
|
||
if $copy_content; then | ||
copy_combined_content_to_clipboard | ||
echo "Combined content of all files copied to clipboard." | ||
fi |