-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew-note
More file actions
executable file
·44 lines (35 loc) · 1.06 KB
/
Copy pathnew-note
File metadata and controls
executable file
·44 lines (35 loc) · 1.06 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
#!/bin/bash
# Source shared configuration
SCRIPT_DIR="$(dirname "$0")"
source "$SCRIPT_DIR/safenotes-config"
# Validate configuration and check tools
if ! validate_config; then
exit 1
fi
if ! check_common_tools; then
exit 1
fi
if ! check_editing_tools; then
exit 1
fi
# Get optional filename parameter
OPTIONAL_NAME="$1"
# Generate filename using shared function
FILENAME=$(generate_filename "$OPTIONAL_NAME")
FILEPATH="$NOTES_DIR/$FILENAME"
# Pre-create encrypted file to avoid recipient prompt
echo "" | gpg --armor --encrypt --trust-model always --recipient "$GPG_RECIPIENT" > "$FILEPATH"
# Open the file with neovim (now it will decrypt automatically without prompting)
nvim "$FILEPATH"
# Check if file is effectively empty after editing (only contains whitespace when decrypted)
if gpg --quiet --decrypt "$FILEPATH" 2>/dev/null | grep -q '[^[:space:]]'; then
# File has content, keep it
:
else
# File is empty or only whitespace, delete it
if command -v trash &> /dev/null; then
trash "$FILEPATH"
else
rm "$FILEPATH"
fi
fi