Skip to content

Instantly share code, notes, and snippets.

@zwhitchcox
Last active November 22, 2023 03:26
Show Gist options
  • Save zwhitchcox/38845d65fd046822cea085d53c047111 to your computer and use it in GitHub Desktop.
Save zwhitchcox/38845d65fd046822cea085d53c047111 to your computer and use it in GitHub Desktop.
copy files to clipboard for chatgpt
#!/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