-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew-til.sh
55 lines (43 loc) · 1.2 KB
/
new-til.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
#!/bin/bash
# Function to get the current date in YYYY-MM-DD format
get_current_date() {
date +"%Y-%m-%d"
}
# Function to create a new Markdown file with YAML front matter
create_markdown_file() {
#todo: check if subdirectory exists first
local path=$1
local filename=$2
local date=$(get_current_date)
# Create the file with the specified path and filename
fullpath="./content/til/${path}/${filename}.md"
touch $fullpath
# Add YAML front matter to the file
echo "---" >> "${fullpath}"
echo "date: ${date}" >> "${fullpath}"
echo "title: " >> "${fullpath}"
echo "tags: []" >> "${fullpath}"
echo "---" >> "${fullpath}"
echo "" >> "${fullpath}"
echo "Created ${fullpath} with YAML front matter."
# open new file in vscode in current directory
code $fullpath .
}
# Usage: new-til.sh <path> <filename>
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <path> <filename>"
exit 1
fi
path=$1
filename=$2
# Check if the specified path exists
if [[ ! -d "$path" ]]; then
# Create the path if it doesn't exist
mkdir -p "$path"
fi
# Check if the path creation was successful
if [[ ! -d "$path" ]]; then
echo "Failed to create the path: $path"
exit 1
fi
create_markdown_file "$path" "$filename"