Created
April 2, 2020 22:37
-
-
Save mpgarate/2216ae5375b735630b05aa4c0469498e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tidy_notes(){ | |
for f in $HOME/notes/*.md $HOME/notes/*.txt; do | |
test -f "$f" || continue | |
echo "$f" || grep "README" && continue | |
f_name=$(basename "$f" | sed -e 's/[^A-Za-z0-9._-]/-/g') | |
echo "$f_name" | |
if [[ ! "$f_name" =~ ^20[0-9][0-9] ]]; then | |
f_date=$(stat -c %y $f | awk '{print $1}') | |
f_time=$(stat -c %y $f | awk '{print $2}' | cut -d '.' -f1 | tr ':' '-') | |
new_file="$HOME/notes/$f_date-$f_name" | |
set -x | |
if [ -f "$new_file" ]; then | |
mv --no-clobber "$f" "$HOME/notes/$f_date.$f_time-$f_name" | |
else | |
mv "$f" "$new_file" | |
fi | |
set +x | |
fi | |
done | |
} | |
onote() { | |
local query=$1 | |
local results=$(find "$HOME/notes/" -iname "*$query*") | |
# passing all results to vim to open in tabs | |
vim $results | |
} | |
note() { | |
local description="$1" | |
tidy_notes | |
local date_time=$(date +'%Y-%m-%d') | |
local file_name="$HOME/notes/$date_time" | |
test -z "$description" || file_name="$file_name-$description" | |
set +x | |
vim "$file_name.md" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment