Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix #2

Merged
merged 8 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Upload MergeClip.zip as Artifact

on:
push:
branches: [ 1.x ]
pull_request:
branches: [ 1.x ]
workflow_dispatch:

jobs:
upload-artifact:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Upload MergeClip.zip as artifact
uses: actions/upload-artifact@v4
with:
name: MergeClip
path: MergeClip.zip
if-no-files-found: error
Binary file modified MergeClip.zip
Binary file not shown.
74 changes: 58 additions & 16 deletions mergeclip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ totalCharacterCount=0
totalFileCount=0
mergedContent=""

# Debug log file
DEBUG_LOG="/tmp/file_merger_debug.log"

# Temporary file for content
TEMP_FILE="/tmp/merged_content.txt"

# Function to log debug information
debug_log() {
echo "$(date): $1" >> "$DEBUG_LOG"
}

debug_log "Script started"

# Function to check if a file is binary
is_binary() {
file --mime-encoding "$1" | grep -q binary
Expand All @@ -18,12 +31,12 @@ process_file() {
local file="$1"

if [ $totalCharacterCount -ge $MAX_CHARS ]; then
echo "Reached character limit. Stopping scan."
debug_log "Reached character limit. Stopping scan."
return 1
fi

if is_binary "$file"; then
echo "Skipping binary file: $file"
debug_log "Skipping binary file: $file"
return 0
fi

Expand All @@ -34,13 +47,14 @@ process_file() {
fileCharCount=${#fileContent}

if [ $((totalCharacterCount + fileCharCount)) -ge $MAX_CHARS ]; then
echo "Adding this file would exceed the character limit. Stopping scan."
debug_log "Adding this file would exceed the character limit. Stopping scan."
return 1
fi

mergedContent+="$fileContent"
totalCharacterCount=$((totalCharacterCount + fileCharCount))
totalFileCount=$((totalFileCount + 1))
debug_log "Processed file: $file"
return 0
}

Expand All @@ -55,7 +69,7 @@ process_directory() {

# Check if arguments are provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <file1> <file2> ... <directory1> <directory2> ..."
debug_log "No arguments provided. Exiting."
exit 1
fi

Expand All @@ -66,22 +80,50 @@ for item in "$@"; do
elif [ -d "$item" ]; then
process_directory "$item"
else
echo "Error: '$item' is not a valid file or directory."
debug_log "Error: '$item' is not a valid file or directory."
fi
done

# Copy to clipboard using pbcopy
echo -e "$mergedContent" | pbcopy
# Write content to temporary file
echo -n "$mergedContent" > "$TEMP_FILE"
debug_log "Content written to temporary file: $TEMP_FILE"

# Attempt to copy to clipboard using pbcopy
debug_log "Attempting to copy to clipboard using pbcopy..."
cat "$TEMP_FILE" | pbcopy
pbcopy_exit_code=$?
debug_log "pbcopy operation completed. Exit code: $pbcopy_exit_code"

# Check if pbcopy was successful
if [ $pbcopy_exit_code -ne 0 ] || [ $(pbpaste | wc -c) -eq 0 ]; then
debug_log "pbcopy failed or clipboard is empty. Trying osascript method..."
osascript -e "set the clipboard to (do shell script \"cat $TEMP_FILE\")"
osascript_exit_code=$?
debug_log "osascript clipboard operation completed. Exit code: $osascript_exit_code"

if [ $osascript_exit_code -ne 0 ]; then
debug_log "Error: Both pbcopy and osascript methods failed."
osascript -e 'display alert "Error" message "Failed to copy content to clipboard. Please check the debug log for more information."'
exit 1
fi
fi

# Get the character count of the clipboard content
clipboardCharCount=$(pbpaste | wc -m)
clipboardCharCount=$(pbpaste | wc -c | tr -d '[:space:]')
debug_log "Characters in clipboard: $clipboardCharCount"

# Output the result
#echo "Total files processed: $totalFileCount"
#echo "Total characters in processed files: $totalCharacterCount"
#echo "Characters copied to clipboard: $clipboardCharCount"
#echo "Merged content has been copied to the clipboard."
# Check if the script is run from Finder

# GUI
# osascript -e "display dialog \"$totalFileCount files merged and copied to clipboard. $totalCharacterCount characters in total.\" buttons {\"OK\"} default button \"OK\""
debug_log "Total files processed: $totalFileCount"
debug_log "Total characters in processed files: $totalCharacterCount"
debug_log "Characters copied to clipboard: $clipboardCharCount"

# Display result using osascript
# osascript -e "display dialog \"$totalFileCount files merged and copied to clipboard. $totalCharacterCount characters in total.\" buttons {\"OK\"} default button \"OK\"" 2>> "$DEBUG_LOG"
# Display result in command line
echo "$totalFileCount files merged and copied to clipboard. $totalCharacterCount characters in total."

# Clean up temporary file
rm "$TEMP_FILE"
debug_log "Temporary file removed"

debug_log "Script completed"
Loading