forked from kitian616/jekyll-TeXt-theme
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathnew-post.sh
More file actions
executable file
·48 lines (37 loc) · 1.2 KB
/
Copy pathnew-post.sh
File metadata and controls
executable file
·48 lines (37 loc) · 1.2 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
#!/bin/bash
set -e
scriptdir=$(cd $(dirname $(readlink -f $0)); pwd -P)
notesdir="$scriptdir"
if [ $# -lt 1 ]; then
echo "Usage: `basename $0` <title> [note-date-YYYY-mm-dd]"
#echo
#echo "OPTIONS"
exit
fi
title="$1"
if [ -z "$2" ]; then
date=`date +%Y-%m-%d`
else
date="$2"
fi
# Convert spaces to dashes and convert title to lowercase
title_dashes=`echo -n "$title" | tr '[:upper:]' '[:lower:]' | tr '[:space:]' '-' | tr -dc '[:alnum:]-'`
filename="$date-${title_dashes}" # file name w/o extension
mdfile="${filename}.md" # file name w/ extension
notepath=$notesdir/$mdfile # full file path
if [ -f "$notepath" ]; then
echo "ERROR: $mdfile already exists in $notesdir. Will not overwrite, so please rename or delete yourself."
exit 1
fi
# Create note from template file
echo "Creating file $mdfile..."
templ=$(cat $notesdir/templ.md | sed "s/insert-title-here/$title/g")
#fulldate=`date "+%A, %B %-d, %Y, %-I:%M%p, at"`
echo "$templ" > "$notepath"
hash_init=`sha256sum $notepath`
vim "$notepath"
hash_mod=`sha256sum $notepath`
if [ "$hash_init" == "$hash_mod" ]; then
rm $notepath
echo "You did not make any changes to '$notepath', so not saving it."
fi