-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathside-notes.sh
More file actions
145 lines (124 loc) · 4.66 KB
/
side-notes.sh
File metadata and controls
145 lines (124 loc) · 4.66 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env zsh
# SideNotes - Lightweight project notes
# https://github.com/pdenya/side-notes
# Configuration
NOTES_BASE_DIR="${SIDENOTES_DIR:-$HOME/Code/SideNotes}"
NOTES_LINK_NAME="SideNotes"
NOTES_EDITOR="${EDITOR:-code}"
# Determine the location of the scripts
# Try to find the scripts directory relative to this file or in ~/.sidenotes/scripts
if [[ -d "${0:A:h}/scripts" ]]; then
SIDENOTES_SCRIPTS_DIR="${0:A:h}/scripts"
elif [[ -d "$HOME/.sidenotes/scripts" ]]; then
SIDENOTES_SCRIPTS_DIR="$HOME/.sidenotes/scripts"
else
echo "Warning: SideNotes scripts directory not found"
SIDENOTES_SCRIPTS_DIR=""
fi
# Export for scripts to use
export SIDENOTES_DIR="$NOTES_BASE_DIR"
export EDITOR="$NOTES_EDITOR"
# Initialize notes for current repository
function notes_init {
if [[ -n "$SIDENOTES_SCRIPTS_DIR" ]] && [[ -x "$SIDENOTES_SCRIPTS_DIR/notes-init.sh" ]]; then
"$SIDENOTES_SCRIPTS_DIR/notes-init.sh" "$@"
else
# Fallback to embedded implementation
local repo_name="${1:-$(basename "$PWD")}"
local note_dir="$NOTES_BASE_DIR/$repo_name"
if [[ -L "$NOTES_LINK_NAME" ]]; then
echo "✓ Notes already initialized"
return 0
fi
mkdir -p "$note_dir"
ln -s "$note_dir" "$NOTES_LINK_NAME"
echo "✓ SideNotes initialized for $repo_name"
fi
}
# Create a new note
function note {
if [[ -n "$SIDENOTES_SCRIPTS_DIR" ]] && [[ -x "$SIDENOTES_SCRIPTS_DIR/note.sh" ]]; then
"$SIDENOTES_SCRIPTS_DIR/note.sh" "$@"
else
# Fallback to embedded implementation
if [[ ! -L "$NOTES_LINK_NAME" ]]; then
echo "Run 'notes_init' first to initialize"
return 1
fi
if [[ -z "$1" ]]; then
echo "Usage: note <slugified-filename>"
echo "Example: note sidenotes-style-adjustments"
echo "Note: Use slugified names (lowercase, hyphens for spaces)"
return 1
fi
local title="$1"
local filename="$NOTES_LINK_NAME/$(date +"%Y-%m-%d_%H-%M")_${title}.md"
cat > "$filename" << EOF
# $title
*$(date +"%Y-%m-%d %H:%M:%S")*
EOF
echo "Created: $filename"
$NOTES_EDITOR "$filename"
fi
}
# Show usage and list notes
function notes {
if [[ -n "$SIDENOTES_SCRIPTS_DIR" ]] && [[ -x "$SIDENOTES_SCRIPTS_DIR/notes.sh" ]]; then
"$SIDENOTES_SCRIPTS_DIR/notes.sh" "$@"
else
# Fallback to embedded implementation
echo "SideNotes - Lightweight project notes"
echo ""
echo "USAGE:"
echo " notes_init [project_name] Initialize notes for current repository"
echo " note <slugified-filename> Create a new note (e.g. note sidenotes-style-adjustments)"
echo " notes Show this help and list existing notes"
echo " notes_latest Open the most recent note"
echo " notes_projects List all projects with notes"
echo ""
echo "NOTE: Use slugified filenames (lowercase, hyphens for spaces)"
echo ""
if [[ ! -L "$NOTES_LINK_NAME" ]]; then
echo "STATUS: Not initialized. Run 'notes_init' first."
return 0
fi
if [[ -z "$(ls -A "$NOTES_LINK_NAME" 2>/dev/null)" ]]; then
echo "NOTES: No notes yet. Create one with 'note <filename>'"
return 0
fi
echo "NOTES:"
ls -1t "$NOTES_LINK_NAME" | sed 's/^/ /'
fi
}
# Open latest note
function notes_latest {
if [[ -n "$SIDENOTES_SCRIPTS_DIR" ]] && [[ -x "$SIDENOTES_SCRIPTS_DIR/notes-latest.sh" ]]; then
"$SIDENOTES_SCRIPTS_DIR/notes-latest.sh" "$@"
else
# Fallback to embedded implementation
if [[ ! -L "$NOTES_LINK_NAME" ]]; then
echo "Run 'notes_init' first to initialize"
return 1
fi
local latest=$(ls -t "$NOTES_LINK_NAME" 2>/dev/null | head -n1)
if [[ -z "$latest" ]]; then
echo "No notes yet"
return 1
fi
$NOTES_EDITOR "$NOTES_LINK_NAME/$latest"
fi
}
# List all projects with notes
function notes_projects {
if [[ -n "$SIDENOTES_SCRIPTS_DIR" ]] && [[ -x "$SIDENOTES_SCRIPTS_DIR/notes-projects.sh" ]]; then
"$SIDENOTES_SCRIPTS_DIR/notes-projects.sh" "$@"
else
# Fallback to embedded implementation
echo "Projects with SideNotes:"
ls -1d "$NOTES_BASE_DIR"/*/ 2>/dev/null | while read -r dir; do
local project=$(basename "$dir")
local count=$(ls -1 "$dir" 2>/dev/null | wc -l)
echo " $project ($count notes)"
done
fi
}