tbh1 / sublime-notes

A syntax designed to bring syntax highlighting to every day note taking.
76 stars 18 forks source link

Support for tags or labels would be great. #35

Open markriggins opened 5 years ago

markriggins commented 5 years ago

I like to be able to search documents quickly by subject, not just file name or contents. One way to handle this is to create folders and subfolders by subject, but it's just too time consuming to do that. Evernote lets you tag the various notes, and then you can search by tag.

So I wrote a little script to help with it

#! /bin/bash

#
# This script searches $NOTES_DIRECTORY for .txt or .notes files
# and moves them to subfolders for the year and month YYYY/MM when
# they were last modified.
#
# also it greps all note files tag like '#tags:t1,t2,...' and 
# writes the unique tags to a file named tags.

set -euo pipefail  # exit on any unexpected failure

NOTES_DIRECTORY=${NOTE_DIRECTORY-$HOME/WorkDocs/Notes}
SUFFIX=notes
THIS_MONTH=$(date +%Y-%m)

cd $NOTES_DIRECTORY

# Move all .txt files to .$SUFFIX
for each in *.txt
do
    new_file_name=$(echo $each | 
        sed -e "s/\.txt\$/.$SUFFIX/g" -e 's/ /-/g' )

    [ -f "$each" ] || continue
    echo "renaming $each  --> $new_file_name"
    mv "$each" "$new_file_name"
done

for each in *.$SUFFIX
do
    date=$(date -r "$each" +%Y-%m );
    _DATES+=($date);
    FILES+=($each);
done

DATES=$(printf "%s\n" "${_DATES[@]}" | sort -u);
for date in ${DATES[@]}; do
    [ $date == $THIS_MONTH ] && continue
    if [ ! -d "$date" ]; then
        mkdir "$date"
    fi
done

for i in  ${FILES[@]}; do
  dest=$(date -r "$i" +%Y-%m)
  [ $dest == $THIS_MONTH ] && continue
  mv $i $dest/$i
done

# write tags report
echo "# This file is an auto-generated list of all tags" > tags
echo "# found in .notes files" >> tags
echo "# " >> tags
echo "# tags:" >> tags
find . -name '*.notes' | 
    xargs cat | 
    egrep '^tags:' | 
    sed -e 's/^tags://' | 
    tr ',' '\012'  | 
    sort -u >> tags