-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_note.sh
executable file
·85 lines (64 loc) · 1.85 KB
/
create_note.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
<<usage
# Commands
> notes - open the notes repo/dir in VS code
> notes new - create a new note in the notes dir with a UUID based on date as the filename
> notes new "this is a post title" - create a new note in the notes dir with the filename being the title converted to a slug, prefixed with UUID based on date
# TODO
- 'if' filename is provided, use that prefixed with date
- 'if' no filename provided, use the UUID as the filename
- prefix filename with date
- 'if' slug has spaces ' ', replace them with hypens '-'
- add template
usage
DATE_UUID=$(date '+%Y%m%d%H%M%S') # 20231119115517
DATE_STRING=$(date '+%Y-%m-%dT%H:%M:%S%:z') # 2023-11-19T11:55:40+02:00
TITLE="$@"
SLUG=$(echo "$@" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | tr " " "-" | tr "[:upper:]" "[:lower:]")
EXTENSION=".md"
FILENAME="${DATE_UUID}-${SLUG}${EXTENSION}"
create_slug() {
# echo ' this is a post ' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | tr " " "-" # this-is-a-post
# use sed to trim space from beginning and end
# use tr to replace spaces with -
# TODO: make the slug lowercase
SLUG=$(echo "$@" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | tr " " "-" | tr "[:upper:]" "[:lower:]")
return $SLUG
}
create_file() {
# if filename is provided, use that prefixed with date
# if no filename provided, use the UUID as the filename
touch "${FILENAME}"
}
add_template() {
echo -e "---
title: ${TITLE}
date: ${DATE_STRING}
uuid: ${DATE_UUID}
slug: ${SLUG}
draft: true
description:
tags:
---
" >> ${FILENAME}
}
open_in_vscode() {
DIR='/media/amna/Files/Sites/notes'
code $DIR
}
create_file
add_template
if [ "$#" == 0 ]; then
open_in_vscode
fi
notes() {
DIR='/media/amna/Files/Sites/notes'
if [ "$#" == 0 ]; then
code $DIR
fi
if [ "$1" == 'new' ]; then
EXT='.md'
PREFIX=$(date '+')
touch
fi
}