<commit_before>#!/bin/bash
VERSION="0.4";

function help() {
    echo "alfred [options] [-f] <file> [-q] <query>";
    echo "";
    echo "  -f  --file     Filename of php file (ex 'script.php')";
    echo "  -h  --help     Show help options (what you're viewing now)";
    echo "  -q  --query    Value to replace {query} with";
    echo "  -v  --version  Return version of script";
}

hput () {
  eval hash"$1"='$2'
}

hget () {
  eval echo '${hash'"$1"'#hash}'
}

FILE='';   # Filename from --file
QUERY='';  # String from --query
OUTPUT=''; # 
VERSION_STR="Version: $VERSION";

# Supported Scripts
hput bash bash
hput sh zsh
hput rb rudy
hput php php
hput py python
hput pl perl
hput scpt osascript

while true ; do
    case "$1" in
        -f )
            FILE=$2
            shift 2
        ;;
        --file )
            FILE=$2
            shift 2
        ;;
        -h )
            #help # Called below
            break
        ;;
        --help )
            #help # Called below
            break
        ;;
        -q )
            QUERY=$2
            shift 2
        ;;
        --query )
            QUERY=$2
            shift 2
        ;;
        -v )
            OUTPUT=$VERSION_STR
            break
        ;;
        --version )
            OUTPUT=$VERSION_STR
            break
        ;;
        *)
            break
        ;;
    esac 
done;

if [[ $FILE ]]; then
    EXT="${FILE##*.}";
    COMMAND=`hget "$EXT"`
    if [[ -z $EXT ]]; then
        echo "Common batman, you need a file extension."
    elif [[ $COMMAND ]]; then
        cat $FILE | sed -e "s/{query}/$QUERY/" > .tmp && $COMMAND .tmp && rm .tmp;
    else
        echo "That script isn't supported. Try .php, .pl, .py, .rb, or .scpt"
    fi
elif [[ $OUTPUT ]]; then
    echo $OUTPUT
else
    # Called from -h, --help, or when no workable options are passed
    help
fi<commit_msg>0.4 / escaping for sed regex<commit_after>#!/bin/bash
VERSION="0.5";

function help() {
    echo "alfred [options] [-f] <file> [-q] <query>";
    echo "";
    echo "  -f  --file     Filename of php file (ex 'script.php')";
    echo "  -h  --help     Show help options (what you're viewing now)";
    echo "  -q  --query    Value to replace {query} with";
    echo "  -v  --version  Return version of script";
}

hput () {
  eval hash"$1"='$2'
}

hget () {
  eval echo '${hash'"$1"'#hash}'
}

FILE='';   # Filename from --file
QUERY='';  # String from --query
OUTPUT=''; # 
VERSION_STR="Version: $VERSION";

# Supported Scripts
hput bash bash
hput sh zsh
hput rb rudy
hput php php
hput py python
hput pl perl
hput scpt osascript

while true ; do
    case "$1" in
        -f )
            FILE=$2
            shift 2
        ;;
        --file )
            FILE=$2
            shift 2
        ;;
        -h )
            #help # Called below
            break
        ;;
        --help )
            #help # Called below
            break
        ;;
        -q )
            QUERY=$2
            shift 2
        ;;
        --query )
            QUERY=$2
            shift 2
        ;;
        -v )
            OUTPUT=$VERSION_STR
            break
        ;;
        --version )
            OUTPUT=$VERSION_STR
            break
        ;;
        *)
            break
        ;;
    esac 
done;

if [[ $FILE ]]; then
    EXT="${FILE##*.}";
    COMMAND=`hget "$EXT"`
    if [[ -z $EXT ]]; then
        echo "Common batman, you need a file extension."
    elif [[ $COMMAND ]]; then
        # Escape $QUERY
        QUERY=$(echo $QUERY | sed -e 's/\//\\\//g')
        cat $FILE | sed -e "s/{query}/$QUERY/" > .tmp && $COMMAND .tmp && rm .tmp;
    else
        echo "That script isn't supported. Try .php, .pl, .py, .rb, or .scpt"
    fi
elif [[ $OUTPUT ]]; then
    echo $OUTPUT
else
    # Called from -h, --help, or when no workable options are passed
    help
fi
{'fraction_non_alphanumeric': 0.1458061144499608, 'fraction_numerical': 0.007839038411288215, 'mean_word_length': 1.4151419558359621, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2907342', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1240, 'n_words': 394}