Last active
November 22, 2023 03:26
-
-
Save zwhitchcox/38845d65fd046822cea085d53c047111 to your computer and use it in GitHub Desktop.
copy files to clipboard for chatgpt
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
#!/bin/zsh | |
# Function to copy content to clipboard | |
copy_to_clipboard() { | |
echo "$1" | pbcopy | |
} | |
# Function to process files and copy to clipboard | |
process_files() { | |
local content="" | |
local is_schema_file=false | |
# Loop through each file passed as an argument | |
for file in "$@"; do | |
if [[ -f $file ]]; then | |
# Check if the current file is schema.prisma | |
if [[ $file == *"schema.prisma"* ]]; then | |
is_schema_file=true | |
else | |
is_schema_file=false | |
fi | |
content+="File: $file\n\n" | |
while IFS= read -r line; do | |
# Check for the generated views line in schema.prisma | |
if $is_schema_file && [[ $line == "// generated views - start"* ]]; then | |
break | |
fi | |
content+="$line\n" | |
done < "$file" | |
content+="\n" | |
fi | |
done | |
# Copy to clipboard | |
copy_to_clipboard "$content" | |
} | |
# Check if any files are provided | |
if [[ -z $1 ]]; then | |
echo "Please provide file(s)." | |
exit 1 | |
fi | |
# Calling the function with the provided files | |
process_files "$@" | |
# Confirm completion | |
echo "Files' contents copied to clipboard." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment