<commit_before>#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# Simple script for capturing screenshots and uploading them or another file
# to a simple file hosting site. imagemagick required
# you will need to edit to work with your site


folder=$(dirname "$0")
archive="$folder/archive"
# WARNING, deleting this file will cause the couter to reset and new
# files to overwrite the old ones.
if [ ! -f "$folder/counter.txt" ]; then
    echo "0" > "$folder/counter.txt"
fi
count=$(cat "$folder/counter.txt")
file_name="SN$(printf %07d "$count")"
((count++))
echo $count > "$folder/counter.txt"

# For my images this seems to be the best compression options, may differ.
PNG_OPTS=( -define "png:compression-level=9"
           -define "png:compression-filter=5"
           -define "png:compression-strategy=1"
)
# this mess will use imagemagik to add a timestamp to the image
timestamp()
{
    height=$(identify -format %h "$file_path");
    width=$(identify -format %w "$file_path");
    # readable text wont fit on something too small so skip
    if (( height <= 25 )) || (( width <= 100 )); then
        notify-send -t 4000 "Image to small for timestamp to be added."
    else
        # smaller images get a  smaller font to make things fit better
        if (( height <= 250 )) || (( width <= 500 )); then
            pntsize=8
            ofst="+2+2"
            srkwdt=1
        else
            pntsize=12
            ofst="+4+4"
            srkwdt=2
        fi
        timestamp=$(date "+%Y-%m-%d %H:%M:%S")
        convert "$file_path" -gravity SouthEast -font Noto-Sans -pointsize\
         "$pntsize" -fill white -stroke black -strokewidth $srkwdt\
         -annotate "$ofst" "$timestamp" -stroke none -annotate "$ofst"\
         "$timestamp" "${PNG_OPTS[@]}" "$file_path"
    fi
}
upload_file_site()
{
    apikey=$(cat "$folder/apikey.txt")
    time_stamp=$(date "+%Y-%m-%d %H:%M:%S")
    notify-send -t 2000 "File is being uploaded..."
    # upload file to site and save response to file and grep url uploaded to
    response=$(curl -s -F "file=@$file_path" -F "apikey=$apikey" \
    https://x88.moe/api/v1/upload.php)
    # get just the url for the file
    url=$(echo "$response" | grep -Po '(?<="url":").*?(?=")')
    # save response so can find/delete it if wanted later.
    printf "\nFile: %s, Time: %s, Response: %s " "$(readlink -f "$file_path")" \
    "$time_stamp" "$response" >> "$folder/history.txt"
    echo -n "$url" | xclip -i -selection c
    notify-send -t 4000 "File Uploaded to: $url and link copied to clipboard"
}
copy_file()
{
    tmpfile_name=$(basename "$file_path")
    exten="${tmpfile_name##*.}"
    new_path="$archive/$file_name.$exten"
    cp "$file_path" "$new_path"
    file_path="$new_path"
}
share_file()
{
    # if no file screenshot was cancelled
    if [ -e "$file_path" ]; then
        if [ "$copy" -eq 1 ]; then
            copy_file
        fi
        upload_file_site
    else
        notify-send -t 4000 "Screenshot Cancelled"
    fi
}

share=0
copy=0
# parse the input<commit_msg>fixed history file weird newline placement<commit_after>#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# Simple script for capturing screenshots and uploading them or another file
# to a simple file hosting site. imagemagick required
# you will need to edit to work with your site


folder=$(dirname "$0")
archive="$folder/archive"
# WARNING, deleting this file will cause the couter to reset and new
# files to overwrite the old ones.
if [ ! -f "$folder/counter.txt" ]; then
    echo "0" > "$folder/counter.txt"
fi
count=$(cat "$folder/counter.txt")
file_name="SN$(printf %07d "$count")"
((count++))
echo $count > "$folder/counter.txt"

# For my images this seems to be the best compression options, may differ.
PNG_OPTS=( -define "png:compression-level=9"
           -define "png:compression-filter=5"
           -define "png:compression-strategy=1"
)
# this mess will use imagemagik to add a timestamp to the image
timestamp()
{
    height=$(identify -format %h "$file_path");
    width=$(identify -format %w "$file_path");
    # readable text wont fit on something too small so skip
    if (( height <= 25 )) || (( width <= 100 )); then
        notify-send -t 4000 "Image to small for timestamp to be added."
    else
        # smaller images get a  smaller font to make things fit better
        if (( height <= 250 )) || (( width <= 500 )); then
            pntsize=8
            ofst="+2+2"
            srkwdt=1
        else
            pntsize=12
            ofst="+4+4"
            srkwdt=2
        fi
        timestamp=$(date "+%Y-%m-%d %H:%M:%S")
        convert "$file_path" -gravity SouthEast -font Noto-Sans -pointsize\
         "$pntsize" -fill white -stroke black -strokewidth $srkwdt\
         -annotate "$ofst" "$timestamp" -stroke none -annotate "$ofst"\
         "$timestamp" "${PNG_OPTS[@]}" "$file_path"
    fi
}
upload_file_site()
{
    apikey=$(cat "$folder/apikey.txt")
    time_stamp=$(date "+%Y-%m-%d %H:%M:%S")
    notify-send -t 2000 "File is being uploaded..."
    # upload file to site and save response to file and grep url uploaded to
    response=$(curl -s -F "file=@$file_path" -F "apikey=$apikey" \
    https://x88.moe/api/v1/upload.php)
    # get just the url for the file
    url=$(echo "$response" | grep -Po '(?<="url":").*?(?=")')
    # save response so can find/delete it if wanted later.
    printf "File: %s, Time: %s, Response: %s\\n" "$(readlink -f "$file_path")" \
    "$time_stamp" "$response" >> "$folder/history.txt"
    echo -n "$url" | xclip -i -selection c
    notify-send -t 4000 "File Uploaded to: $url and link copied to clipboard"
}
copy_file()
{
    tmpfile_name=$(basename "$file_path")
    exten="${tmpfile_name##*.}"
    new_path="$archive/$file_name.$exten"
    cp "$file_path" "$new_path"
    file_path="$new_path"
}
share_file()
{
    # if no file screenshot was cancelled
    if [ -e "$file_path" ]; then
        if [ "$copy" -eq 1 ]; then
            copy_file
        fi
        upload_file_site
    else
        notify-send -t 4000 "Screenshot Cancelled"
    fi
}

share=0
copy=0
# parse the input
{'fraction_non_alphanumeric': 0.1482028557360906, 'fraction_numerical': 0.0160840308550796, 'mean_word_length': 2.7945205479452055, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '573574', 'n_tokens_mistral': 2076, 'n_tokens_neox': 1979, 'n_words': 646}