-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy_to_clipboard.sh
executable file
·44 lines (36 loc) · 1.19 KB
/
copy_to_clipboard.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/zsh
# Define the directory to list files from
DIRECTORY=${1:-$(pwd)} # Use current directory if no argument is given
# Check if the directory exists
if [ ! -d "$DIRECTORY" ]; then
echo "Directory $DIRECTORY does not exist."
exit 1
fi
# Initialize output with a header for the file list
OUTPUT="List of Files Included:\n\n"
FILES_LIST=""
# Gather the list of files recursively
while IFS= read -r FILE; do
if [ -f "$FILE" ]; then
FILES_LIST+="$(realpath "$FILE")\n"
fi
done < <(find "$DIRECTORY" -type f)
# Add file list to the output
if [ -z "$FILES_LIST" ]; then
echo "No files found in $DIRECTORY."
exit 1
else
OUTPUT+="$FILES_LIST\n\n"
fi
# Process and add the content of each file to the output
while IFS= read -r FILE; do
if [ -f "$FILE" ]; then
OUTPUT+="--- Start of File: $FILE ---\n\n"
OUTPUT+="$(cat "$FILE")\n"
OUTPUT+="\n--- End of File: $FILE ---\n\n"
fi
done < <(find "$DIRECTORY" -type f)
# Copy to clipboard
echo -e "$OUTPUT" | pbcopy # For macOS
# echo -e "$OUTPUT" | xclip -selection clipboard # For Linux with xclip
echo "All files from $DIRECTORY (recursively) and their contents have been copied to the clipboard."