<commit_before>#!/bin/bash

# This will run before any command is executed.
pre() {
  if [ -z "$R_AT_PROMPT" ]; then
    return
  fi
  unset R_AT_PROMPT

  # Keep reference to what command was executed
  LAST_CMD="${1##*/}"
  local cmd=$*

  # TODO Don't add if the status errored
  # Add current directory and command to `r`
  r --add "$(\pwd):$cmd"
}

# Set trap to reun pre before command
trap 'pre $BASH_COMMAND' DEBUG

# This will run after the execution of the previous full command line.  We don't
# want `post` to execute when first starting a bash session (FIRST_PROMPT)
R_FIRST_PROMPT=1
post() {
  R_AT_PROMPT=1

  if [ -n "$R_FIRST_PROMPT" ]; then
    unset R_FIRST_PROMPT
    return
  fi

  # Test if LAST_CMD was r then run any command selected
  if [ "$LAST_CMD" = "r" ]; then
    last_r_cmd=$(r --command)
    if [ -z "$last_r_cmd" ]; then
      return
    fi

    eval $last_r_cmd

    return
  fi
}
<commit_msg>Storingn last r command executed in bash history<commit_after>#!/bin/bash

# This will run before any command is executed.
pre() {
  if [ -z "$R_AT_PROMPT" ]; then
    return
  fi
  unset R_AT_PROMPT

  # Keep reference to what command was executed
  LAST_CMD="${1##*/}"
  local cmd=$*

  # TODO Don't add if the status errored
  # Add current directory and command to `r`
  r --add "$(\pwd):$cmd"
}

# Set trap to reun pre before command
trap 'pre $BASH_COMMAND' DEBUG

# This will run after the execution of the previous full command line.  We don't
# want `post` to execute when first starting a bash session (FIRST_PROMPT)
R_FIRST_PROMPT=1
post() {
  R_AT_PROMPT=1

  if [ -n "$R_FIRST_PROMPT" ]; then
    unset R_FIRST_PROMPT
    return
  fi

  # Test if LAST_CMD was r then run any command selected
  if [ "$LAST_CMD" = "r" ]; then
    last_r_cmd=$(r --command)
    if [ -z "$last_r_cmd" ]; then
      return
    fi

    # execute command
    eval $last_r_cmd

    # save command to bash history
    history -s $last_r_cmd

    return
  fi
}

{'fraction_non_alphanumeric': 0.10121457489878542, 'fraction_numerical': 0.003036437246963563, 'mean_word_length': 3.0020242914979756, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1123195', 'n_tokens_mistral': 731, 'n_tokens_neox': 685, 'n_words': 253}