-
Notifications
You must be signed in to change notification settings - Fork 1
/
mn
executable file
·164 lines (151 loc) · 3.21 KB
/
mn
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
# Initialize variables as empty. Some will have default values, such as directory.
# I wouldn't change too many of these, maybe the directory if you want.
# It'd be cool if we could upload to Google Drive, S3, or something.
DATE=$(date "+%Y%m%d%H%M%S")
DIRECTORY=~/Notes/
SUBJECT=''
TOPIC=''
SYNC=''
BROWSE=''
FIND=''
FILE=''
JOT=''
REPO='https://github.com/luthes/makenotes/'
HELP=$'mn - make notes - Steven Luther
Arguments:
-s: subject (Required)
-t: topic (Required)
-g: git sync
- Be careful with this, it will push everything the directory.
-d: list notes in directory
-e: edit file if its created
-b: Browse directory
-f: find in notes titles and contents
-j: quick jot to $DIR/jots/
-l: execute tree on ~/Notes directory'
create_notes() {
# Create the notes files and directories.
if [ -z $SUBJECT ] || [ -z $TOPIC ]
then
echo 'Creating notes requires both the -s and -t arguments.'
else
mkdir -p ~/Notes/$SUBJECT
FILE=~/Notes/$SUBJECT/$TOPIC-$DATE.md
touch $FILE
echo $"# $SUBJECT -- $TOPIC -- $DATE
----------
" >> $FILE
echo "Created file: $FILE"
fi
}
list_directory() {
# This should list the Notes directory in the terminal
# I don't like this. Even if ti would work, it's cluttery. I might user tree.
# I haven't decided yet.
for i in $(ls -lsa)
do
echo $i
ls -lsa $i
done
}
browse() {
#This opensVim on the default directory top level directory so we can browse, and select which file we want to edit.
$EDITOR $DIRECTORY
}
sync() {
# Sync the files to github.
if [ ! -d "$DIRECTORY/.git/" ]
then
echo 'Initializing directory...'
git clone $REPO $DIRECTORY
else
(cd $DIRECTORY
git pull origin master
git add *
git commit -m 'Automated Sync'
git push origin master
)
fi
}
edit() {
$EDITOR $(find ~/Notes -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head | awk '{ print $4 }')
}
jot() {
# This could be nicer.
printf "Jotting $STRING to $FILE"
mkdir -p $DIRECTORY/jots/
touch $DIRECTORY/jots/$DATE-jot
echo $JOT >> $DIRECTORY/jots/$DATE-jot
}
get_jots() {
printf "Getting all jots"
for i in $(find $DIRECTORY);
do
echo "Jot $i\n"
cat $i
done
}
find_notes() {
# Find Matching Titles
echo 'Matched File Titles: '
find $DIRECTORY -not -path '/\.*' -type f -name $FIND
# Find Matching Strings
echo 'Matching content: '
grep -rn --exclude-dir='.*' --exclude '.*' $FIND $DIRECTORY
}
# Show help if no options passed
if [[ ! $@ =~ ^\-.+ ]]
then
echo "$HELP"
fi
#Do things for arguments
while getopts ":s:t:gdbf:jel" opt; do
case $opt in
s)
# Subject
SUBJECT=$OPTARG
;;
t)
#Topic
TOPIC=$OPTARG
create_notes
;;
g)
#Sync
SYNC=$OPTARG
sync
;;
d)
#Directory
DIRECTORY=$OPTARG
list_directory
;;
e)
#Bool - Edit file immediately.
edit
;;
b)
#Browse with Vim
BROWSE=$OPTARG
browse
;;
f)
#find
FIND=$OPTARG
find_notes
;;
l)
#list notes
tree ~/Notes
;;
j)
#jots
JOT=$OPTARG
jot
;;
*)
echo "$HELP"
;;
esac
done