<commit_before>#!/bin/bash

_scriptname=$(basename $0)
usage () {
    sed -e 's/^//' <<End
Usage: $_scriptname [-ehl] [-a text] [-f file] [-g pattern]
-a append text to file
-e edit text file using $EDITOR 
-f use file
-g grep for <pattern> in text
-h show help
End
    exit 1
}

check_textfile () {
if [ ! -f "$1" ]; then
    echo "creating text file: $1"
    touch "$1" || { echo "error creating text file $1"; exit 1; }
    chmod 644 "$1"
fi
}

datetime=$(date "+%Y-%m-%d %H:%M")
action="list"
textfile=""
pattern=""
while getopts :a:ef:g:h opt
do case "$opt" in
    a) action="add";;
    e) action="edit";;
    f) textfile="$OPTARG" ;;
    g) 
        action="grep"
        pattern="$OPTARG" ;;
    h) action="help";;
    \:) 
        printf "argument required for option '%s'\n" $OPTARG
        usage;;
    \?) 
        printf "unknown option '%s'\n" $OPTARG
        usage;;
    esac
done

if [ -z "$textfile" ]; then
    echo "error: text file name required"
    usage
fi

check_textfile "$textfile"

case $action in
    help) usage;;
    edit) $EDITOR "$textfile";;
    add) 
        shift $((OPTIND-1))
        if [ -z "$@" ]; then
            echo "error: nothing to add"
            usage
        fi
        echo "$datetime $*" >> "$textfile"
        ;;
    grep)
        shift $((OPTIND-1))
        if [ -z "$@" ]; then
            echo "error: nothing to search for"<commit_msg>Fix bug adding text to file<commit_after>#!/bin/bash

_scriptname=$(basename $0)
usage () {
    sed -e 's/^//' <<End
Usage: $_scriptname [-ehl] [-a text] [-f file] [-g pattern]
-a append text to file
-e edit text file using $EDITOR 
-f use file
-g grep for <pattern> in text
-h show help
End
    exit 1
}

check_textfile () {
if [ ! -f "$1" ]; then
    echo "creating text file: $1"
    touch "$1" || { echo "error creating text file $1"; exit 1; }
    chmod 644 "$1"
fi
}

datetime=$(date "+%Y-%m-%d %H:%M")
action="list"
textfile=""
pattern=""
while getopts :aef:g:h opt
do case "$opt" in
    a) action="add";;
    e) action="edit";;
    f) textfile="$OPTARG" ;;
    g) 
        action="grep"
        pattern="$OPTARG" ;;
    h) action="help";;
    \:) 
        printf "argument required for option '%s'\n" $OPTARG
        usage;;
    \?) 
        printf "unknown option '%s'\n" $OPTARG
        usage;;
    esac
done

if [ -z "$textfile" ]; then
    echo "error: text file name required"
    usage
fi

check_textfile "$textfile"

case $action in
    help) usage;;
    edit) $EDITOR "$textfile";;
    add) 
        shift $((OPTIND-1))
        text="$@"
        if [ -z "$text" ]; then
            echo "nothing to add"
            usage
        fi
        echo "$datetime $text" >> "$textfile"
        ;;
    grep)
        shift $((OPTIND-1))
        if [ -z "$@" ]; then
            echo "error: nothing to search for"
{'fraction_non_alphanumeric': 0.1711743772241993, 'fraction_numerical': 0.009252669039145907, 'mean_word_length': 2.1584269662921347, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '1717271', 'n_tokens_mistral': 1015, 'n_tokens_neox': 979, 'n_words': 322}