-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup-notes.sh
65 lines (56 loc) · 2.14 KB
/
cleanup-notes.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
#!/bin/bash
# Function to clean up metadata from notes by removing "(Metadata: ...)"
cleanup_notes() {
local file="$1"
local cleaned_notes=""
# Ensure the file exists before attempting to clean it
if [ ! -f "$file" ]; then
echo "File not found: $file"
return
fi
# Use sed to remove only the "(Metadata: ...)" part, leaving the rest intact
cleaned_notes=$(sed 's/(Metadata:.*)//g' "$file")
# Debugging: Display cleaned notes if in DEBUG mode
if [ "$DEBUG" = true ]; then
echo -e "${GREEN}Cleaned notes for $file:${RESET}\n$cleaned_notes"
fi
# Overwrite the original file with cleaned notes
echo "$cleaned_notes" > "$file"
}
# Determine the appropriate date command for macOS (Darwin) or other systems
if [[ "$(uname)" == "Darwin" ]]; then
date_cmd="gdate"
else
date_cmd="date"
fi
# Get month as two digits and written name
month_num=$($date_cmd "+%m")
month=$($date_cmd "+%B" | tr '[:upper:]' '[:lower:]')
# Determine file paths based on the existence of start and end dates
if [ -n "$start_day" ] && [ -n "$end_day" ]; then
# Multi-day file format
file_path="$HOME/Documents/Brain dump/Päivän suunnittelu/${start_day}-${end_day} (useampi päivä).md"
cleanup_notes "$file_path"
else
# Single-day file format
if [[ "$(uname)" == "Darwin" ]]; then
filename=$(gdate -d "${start_day:-$(gdate "+%Y-%m-%d")}" "+%Y-%m-%d")
else
filename=$(date -d "${start_day:-$(date "+%Y-%m-%d")}" "+%Y-%m-%d")
fi
# Create directory structure
year=$($date_cmd "+%Y")
month_num=$($date_cmd "+%m")
mkdir -p "$HOME/Documents/Brain dump/Päivän suunnittelu/$year/$month_num"
# Set file path with proper date format
if [[ "$(uname)" == "Darwin" ]]; then
# macOS version
file_path="$HOME/Documents/Brain dump/Päivän suunnittelu/$year/$month_num/$($date_cmd "%-d.%-m.%Y").md"
else
# Linux version - remove leading zeros with sed
day=$($date_cmd -d "$start_day" "+%d" | sed 's/^0//')
month=$($date_cmd -d "$start_day" "+%m" | sed 's/^0//')
file_path="$HOME/Documents/Brain dump/Päivän suunnittelu/$year/$month_num/${day}.${month}.$($date_cmd -d "$start_day" "+%Y").md"
fi
cleanup_notes "$file_path"
fi