<commit_before>#!/usr/bin/env bash

#####
## VARIABLES
###

DBDIR=`cat Makefile |grep "^DBDIR[ ]*="|cut -d'=' -f2`
SRCDIR=`cat Makefile |grep "^SRCDIR[ ]*="|cut -d'=' -f2`
LIMIT='255'

#####
## TEST
###

if ! test -d ${DBDIR};then
  echo "Database directory is missing! It's useful for posts data."
  exit 1
elif ! test -d ${SRCDIR};then
  echo "Source directory is missing! It's useful for posts."
fi

#####
## BEGIN
###

# Fetch data
read -p "Title: " title
read -p "Description: " desc
read -p "Date: " date
timestamp=`date +'%s'`

# code retrived from Nanoblogger translit_text method with a little improvement for double "_"
nonascii="${title//[a-zA-Z0-9_-]/}" # isolate all non-printable/non-ascii characters
new_name=$(echo "${title:0:$LIMIT}" |sed -e "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/; s/[\`\~\!\@\#\$\%\^\*\(\)\+\=\{\}\|\\\;\:\'\"\,\<\>\/\?]//g; s/ [\&] / and /g; s/^[ ]//g; s/[ ]$//g; s/[\.]/_/g; s/\[//g; s/\]//g; s/ /_/g; s/[$nonascii ]/_/g" |sed -e '/[\_\-]*$/ s///g; /[\_\-]$/ s///g' |sed -e 's/__/_/g')

# db filename
dbfile="${DBDIR}/${timestamp},${new_name}.mk"
echo ${dbfile}
# filename
file="${SRCDIR}/${new_name}.md"
# test that files doesn't exists
if test -f ${dbfile};then
  echo "This post already exists: '${title}'"
  exit 1
elif test -f ${file};then
  echo "This post already exists: '${title}'"
  exit 1
fi

# create db file
echo "TITLE=\"${title}\"" > ${dbfile}
echo "DESCRIPTION=\"${desc}\"" >> ${dbfile}
echo "DATE=\"${date}\""

# create src file
echo "# ${title}" >> ${file}
echo "" >> ${file}
echo "Type your text in markdown format here" >> ${file}
vi ${file}

#####
## END
###

exit 0<commit_msg>[IMP] Take user's default editor to create new post<commit_after>#!/usr/bin/env bash

#####
## VARIABLES
###

DBDIR=`cat Makefile |grep "^DBDIR[ ]*="|cut -d'=' -f2`
SRCDIR=`cat Makefile |grep "^SRCDIR[ ]*="|cut -d'=' -f2`
LIMIT='255'
YOUR_EDITOR=`which nano`

#####
## TEST
###

edit=${EDITOR:-$YOUR_EDITOR}

if [ -z "$edit" ]; then
  echo "No editor found! Please config EDITOR in your .bashrc or edit YOUR_EDITOR in '`basename $0`' script."
  exit 1
fi

if ! test -d ${DBDIR};then
  echo "Database directory is missing! It's useful for posts data."
  exit 1
elif ! test -d ${SRCDIR};then
  echo "Source directory is missing! It's useful for posts."
fi

#####
## BEGIN
###

# Fetch data
read -p "Title: " title
read -p "Description: " desc
read -p "Date: " date
timestamp=`date +'%s'`

# code retrived from Nanoblogger translit_text method with a little improvement for double "_"
nonascii="${title//[a-zA-Z0-9_-]/}" # isolate all non-printable/non-ascii characters
new_name=$(echo "${title:0:$LIMIT}" |sed -e "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/; s/[\`\~\!\@\#\$\%\^\*\(\)\+\=\{\}\|\\\;\:\'\"\,\<\>\/\?]//g; s/ [\&] / and /g; s/^[ ]//g; s/[ ]$//g; s/[\.]/_/g; s/\[//g; s/\]//g; s/ /_/g; s/[$nonascii ]/_/g" |sed -e '/[\_\-]*$/ s///g; /[\_\-]$/ s///g' |sed -e 's/__/_/g')

# db filename
dbfile="${DBDIR}/${timestamp},${new_name}.mk"
echo ${dbfile}
# filename
file="${SRCDIR}/${new_name}.md"
# test that files doesn't exists
if test -f ${dbfile};then
  echo "This post already exists: '${title}'"
  exit 1
elif test -f ${file};then
  echo "This post already exists: '${title}'"
  exit 1
fi

# create db file
echo "TITLE=\"${title}\"" > ${dbfile}
echo "DESCRIPTION=\"${desc}\"" >> ${dbfile}
echo "DATE=\"${date}\""

# create src file
echo "# ${title}" >> ${file}
echo "" >> ${file}
echo "Type your text in markdown format here" >> ${file}
${edit} ${file}

#####
## END
###

exit 0
{'fraction_non_alphanumeric': 0.2579465541490858, 'fraction_numerical': 0.0073136427566807315, 'mean_word_length': 3.594315245478036, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '3901091', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1403, 'n_words': 394}