<commit_before>#!/bin/sh

if [ "x"$1 != "x" ]; then
    CONTAINER_NAME="keep_${USER}_${1}"

    # have a container name.  does it already exist?
    CONTAINER_ID=`docker ps -a | grep $CONTAINER_NAME | awk '{print $1}'`

echo "CONTAINER_ID = $CONTAINER_ID"

    if [ "x"$CONTAINER_ID != "x" ]; then
        # conatiner exists, just try to start it
        # note, if it's already running this has no impact
        CMD="docker start $CONTAINER_ID"
    else
        # doesn't exist, start a new named container
        CMD="docker run -i -t -e DISPLAY=$DISPLAY -u $USER -v /tmp/.X11-unix:/tmp/.X11-unix --name=\"$CONTAINER_NAME\" $USER/jbds /home/$USER/jbdevstudio/studio/jbdevstudio"
    fi
else
    # no name specified, destroy on shutdown
    CMD="docker run -i -t -e DISPLAY=$DISPLAY -u $USER -v /tmp/.X11-unix:/tmp/.X11-unix --rm $USER/jbds /home/$USER/jbdevstudio/studio/jbdevstudio"
fi

echo "COMMAND: $CMD"
exec $CMD

<commit_msg>Much better run.sh: * if named container already exists and is running, script exits * if named container already exists but is not running, script preserves state before starting container * at end, saves state by committing container as tag<commit_after>#!/bin/sh

if [ "x"$1 != "x" ]; then
    CONTAINER_NAME="keep_${USER}_${1}"

    # have a container name.  is it already running?
    CONTAINER_ID=`docker ps | grep $CONTAINER_NAME | awk '{print $1}'`

    if [ "x"$CONTAINER_ID != "x" ]; then
        # conatiner exists and is running! stop!
        echo "Container is already running!  ID=$CONTAINER_ID, Name=$CONTAINER_NAME"
        exit 1
    fi

    # container isn't running, but does it exist?
    CONTAINER_ID=`docker ps -a | grep $CONTAINER_NAME | awk '{print $1}'`

    if [ "x"$CONTAINER_ID != "x" ]; then
        # container exists (stopped)

        # this means tagging didn't happen last run
        # recover by tagging and then use that tag for next start
        CMD="${CMD}docker commit -a \"$USER\" $CONTAINER_NAME $USER/jbds:$1;"

        # and then remove the container
        CMD="${CMD}docker rm $CONTAINER_NAME;"
    fi

    IMAGE_TAG=`docker images | grep "^$USER/jbds" | awk '{print $2}' | grep "^${1}$"`

    if [ "x"$IMAGE_TAG != "x" ]; then
        # tag exists, start from the tag
        CMD="${CMD}docker run -i -t -e DISPLAY=$DISPLAY -u $USER -v /tmp/.X11-unix:/tmp/.X11-unix --name=\"$CONTAINER_NAME\" $USER/jbds:$IMAGE_TAG /home/$USER/jbdevstudio/studio/jbdevstudio;"
    else
        # tag doesn't exist yet, start from base image
        CMD="${CMD}docker run -i -t -e DISPLAY=$DISPLAY -u $USER -v /tmp/.X11-unix:/tmp/.X11-unix --name=\"$CONTAINER_NAME\" $USER/jbds /home/$USER/jbdevstudio/studio/jbdevstudio;"
    fi

    CMD="${CMD}docker commit -a \"$USER\" $CONTAINER_NAME $USER/jbds:$1;docker rm $CONTAINER_NAME;"
else
    # no name specified, destroy on shutdown
    CMD="${CMD}docker run -i -t -e DISPLAY=$DISPLAY -u $USER -v /tmp/.X11-unix:/tmp/.X11-unix --rm $USER/jbds /home/$USER/jbdevstudio/studio/jbdevstudio;"
fi

IFS=";"
for x in $CMD;
do
    echo ">>> START: $x"
    eval $x
    echo "<<< DONE"
done


{'fraction_non_alphanumeric': 0.14949951566031644, 'fraction_numerical': 0.010332579916047788, 'mean_word_length': 2.987129987129987, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '2685740', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1076, 'n_words': 326}