Skip to content

Commit 52751f3

Browse files
authored
Merge pull request #9 from aviaryan/tree-1.0.0
Release a quick v0.9 because why not
2 parents a064d84 + d8906be commit 52751f3

File tree

9 files changed

+451
-84
lines changed

9 files changed

+451
-84
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ __pycache__
55
*.sublime-workspace
66
.DS_Store
77
FLAG_FILE
8+
settings.json

README.markdown

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,34 @@
11
# Sublime Notebook
22

3-
Sublime Notebook is an attempt to use Sublime Text as a complete note taking application.
4-
5-
**Read the Medium post for setup instructions**:
6-
https://medium.com/aviaryan/sublime-notebook-an-attempt-to-use-sublime-text-as-my-note-taking-application-b8d846c47905#.hy8alq2ip
7-
8-
9-
## Features
10-
11-
* Search across all notes
12-
* Hierarchical organization and display of notes
13-
* Password based encryption
14-
* Cloud sync
15-
* Markdown based markup and syntax highlighting
3+
**v0.9**
164

5+
Sublime Notebook is an attempt to use Sublime Text as a complete note taking application.
176

18-
### Updating SublimeNotebook or changing password
7+
> Blog post for v0.3.0 (no longer recommended) https://medium.com/aviaryan/b8d846c47905#.hy8alq2ip
198
20-
* To update your installation of Sublime Notebook, decrypt your existing notes using old manager.py, then force exit the script before encrypting. Then update the script files from this repo and start `manager.py` to re-encrypt your notes.
21-
* Same method can be used if you want to change the password used to secure the notes.
229

10+
## Why did you build this?
2311

24-
### FAQ
12+
I have been note-taking for as long as I started using computers. I use notes mostly for technical stuff, but these days I am using notes to record all kinds of information like journals, ideas, snippets etc. In my career, I have tried a number of note-taking tools like OneNote, Evernote, CintaNotes, SimpleNote, Cherrytree, Google Keep, etc. But I have never been satisfied with them mainly because -
2513

26-
* Only *.txt and *.md files are detected as notes.
27-
* You don't need to be in decrypted state to create a new note. Even when in encrypted state, you can create a note. When manager.py starts decrypting the notes,
28-
this new file will be ignored and will be encrypted when it's time to encrypt.
14+
1. I don't have any control over how or where my notes are stored. - What if the company closes or the developer stops building the product?
15+
2. Most of these services are paid or work on only certain Operating Systems. And even if they are truly free and cross-platform, they lack critical features like fast full notebook search or hierarchical organization.
2916

17+
Because of these reasons, I had to lose my notes a number of times and was forced to start from scratch. This was frustrating, and finally, I decided to do something about it.
3018

31-
### <a name="mdext"></a>Setup Markdown Extended for highlighting md files
19+
The result is this project, a wrapper/idea that converts my favorite text editor, Sublime Text, to a feature-rich note-taking tool. Sure it might not be as polished as all those premium note-taking tools, but it works and that too in the way I want it to.
3220

33-
* Install the packages from here.
3421

35-
* [Sublime Markdown Extended](https://github.com/jonschlinkert/sublime-markdown-extended)
36-
* [Sublime Monokai Extended](https://github.com/jonschlinkert/sublime-monokai-extended) - companion to the first package.
22+
## Features
3723

38-
* Make Sublime Markdown Extended as default language for markdown.
24+
* Faaaast Search across all notes (thanks to Sublime Text)
25+
* Hierarchical organization and display of notes
26+
* Password based encryption for notes
27+
* Cloud sync (Dropbox, Google Drive, Box, etc)
28+
* Automatic git backup (to Github, Gitlab, your own private git server, etc)
29+
* Markdown based markup and code syntax highlighting
3930

40-
> Navigate through the following menus in Sublime Text: View -> Syntax -> Open all with current extension as... -> Markdown Extended
4131

42-
* Make Sublime Monokai Extended default theme for Markdown extended. Open `Settings - Syntax Specific` from preferences and update the file as follows.
32+
## Documentation
4333

44-
```js
45-
{
46-
"color_scheme": "Packages/Monokai Extended/Monokai Extended.tmTheme",
47-
"extensions":
48-
[
49-
"md"
50-
]
51-
}
52-
```
34+
Find the docs in the [sublime_notebook/docs](sublime_notebook/docs) folder.

manager.py

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,7 @@
11
#!/Users/aviaryan/miniconda3/bin/python
22

3-
'''
4-
Sublime Notebook Manager
5-
v0.2.1
6-
'''
7-
8-
import os
9-
from sys import exit
10-
from cryptlib import get_file_list, encode, update_file, get_key, decode
11-
12-
FLAG = 'FLAG_FILE'
13-
14-
15-
def createFlagFile():
16-
fptr = open(FLAG, 'w')
17-
fptr.write('')
18-
fptr.close()
3+
from sublime_notebook import sublime_notebook
194

205

216
if __name__ == '__main__':
22-
23-
if not os.path.exists(FLAG):
24-
# new case
25-
# or decrypted state in power fail
26-
print('Not encrypted, encrypting....')
27-
key = get_key()
28-
print('Re-enter key')
29-
key2 = get_key()
30-
if key != key2:
31-
print('Keys don\'t match, exiting')
32-
exit(1)
33-
update_file(encode, get_file_list(), key2)
34-
createFlagFile()
35-
else:
36-
# encrypted already
37-
print('Encrypted, give key to unlock')
38-
key = get_key()
39-
failStatus = update_file(decode, get_file_list(), key)
40-
if failStatus:
41-
print('You entered wrong key. FO')
42-
exit(2)
43-
os.remove(FLAG)
44-
# decoded, wait to close
45-
print('Notes have been decrypted')
46-
ans = ''
47-
while ans != 'e':
48-
ans = input('Press e to encrypt again > ')
49-
# encrypt
50-
update_file(encode, get_file_list(), key)
51-
createFlagFile()
7+
sublime_notebook.main()

sublime_notebook/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SETTINGS_PATH = 'sublime_notebook/settings.json'
2+
VERSION = 0.9

cryptlib.py renamed to sublime_notebook/cryptlib.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import base64
2-
from getpass import getpass
32
import os
3+
import re
4+
from getpass import getpass
5+
from .settings import Settings
6+
47

58
EXTRA_STR = 'ENCo0D#DT{xTCh$cKe>'
69
ENCODED_IDF = '=*=EnC0d3dH3aDer==*'
@@ -42,13 +45,21 @@ def decode(key, enc):
4245

4346
def get_file_list():
4447
listFiles = []
48+
sts = Settings()
49+
# loop through directory
4550
for dirpath, dnames, fnames in os.walk('./'):
46-
if dirpath.endswith('/public') or (dirpath.find('/public/') > -1): # skip public notes
51+
dirname = dirpath.replace('./', '', 1)
52+
dirname = re.sub(r'/.*$', '', dirname)
53+
# print(dirname)
54+
if dirname.startswith('.'): # hidden like .git
55+
continue
56+
if not sts.check_folder_private(dirname):
4757
continue
4858
for f in fnames:
4959
if not (f.endswith('.txt') or f.endswith('.md')):
5060
continue
5161
listFiles.append(os.path.join(dirpath, f))
62+
# print(listFiles)
5263
return listFiles
5364

5465

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# Documentation
2+
3+
## Table of Contents
4+
5+
* [Requirements](#rq)
6+
* [Getting Started](#gs)
7+
* [Accessing your notes](#ac)
8+
* [Encrypting your notes](#en)
9+
* [Note taking features](#nt)
10+
* [Changing SublimeNotebook password](#cp)
11+
* [Customizing which folders are encrypted](#custen)
12+
* [Automatic git backups](#git)
13+
* [Setting up better Markdown highlighting in Sublime Text](#mdext)
14+
* [FAQ](#faq)
15+
16+
17+
<a name="rq"></a>
18+
## Requirements
19+
20+
The requirements for using this tool are as follows. Make sure to have them installed before proceeding to the next section.
21+
22+
* Sublime Text
23+
* Python 3
24+
* [Optional] A cloud sync application setup (Dropbox, Google Drive, OneDrive etc)
25+
26+
27+
<a name="gs"></a>
28+
## Getting started
29+
30+
The first step is downloading the release from https://github.com/aviaryan/SublimeNotebook/releases/latest.
31+
32+
Then you extract the zip file and put the contents in a cloud synced or local folder of your choice.
33+
34+
Done! You can now create any number of notes in that folder. For hierarchy, you can use folders and sub-folders. Notes can be txt or md files and they will be encrypted with your password.
35+
36+
![Sublime Notebook: how it looks like](https://user-images.githubusercontent.com/4047597/35737506-c78a8d0a-0851-11e8-8d90-cd71117b08c7.png)
37+
38+
39+
<a name="ac"></a>
40+
## Accessing your notes
41+
42+
To access your notes, we will use the Projects feature of Sublime Text.
43+
44+
Open Sublime Text and click on "Open Project" in the Project menu.
45+
46+
Browse for the `notebook.sublime-project` file in the folder you downloaded and open it. Now open the Sidebar (View -> Sidebar). You will see all your notes presented there with the hierarchy.
47+
48+
Whenever you want to open your Sublime Notebook, you can use the switch project shortcut (Cmd-Ctrl-P or Ctrl-Alt-P) and select `notebook.sublime-project` to switch to the Notebook project.
49+
50+
![Project Selector](https://user-images.githubusercontent.com/4047597/35473121-4556dd7a-03a1-11e8-8c3a-6e85592d5d5f.png)
51+
52+
53+
<a name="en"></a>
54+
## Encrypting your notes
55+
56+
To encrypt or decrypt notes, you use the `manager.py` file located in the notebook root. It runs in Python 3 and requires no additional dependencies.
57+
I recommend changing the first line of the file to point to your interpreter.
58+
59+
```python
60+
#!/Users/aviaryan/miniconda3/bin/python
61+
```
62+
63+
To run `manager.py`, you can use the shortcut Ctrl-B (Cmd-B on OSX) to launch a terminal window in the `manager.py`'s directory.
64+
65+
Then use `python manager.py` or `./manager.py` to run the script.
66+
67+
When it runs for the first time, it will find the notes and ask you a password for encryption.
68+
After getting the password, it will encrypt all non-public notes using that password.
69+
In the subsequent runs, `manager.py` will work as an un-locker where it will ask password to decrypt the notes and then pause its execution.
70+
Now you can view and edit your notes and then later on encrypt them again by entering 'e' in the prompt.
71+
72+
![screen shot 2018-01-27 at 8 06 07 pm](https://user-images.githubusercontent.com/4047597/35472896-897a22a4-039d-11e8-9b1d-153c06bc203e.png)
73+
74+
75+
<a name="nt"></a>
76+
## Note taking features
77+
78+
To search through all your notes, use the Sublime Text’s search in project feature (Ctrl-Shift-F or Cmd-Shift-F).
79+
80+
You can use the Sublime Text sidebar to view your notes in a hierarchical fashion.
81+
82+
Store the folder in Dropbox, Google Drive or Box to have it on all your computers (as well as secure a backup).
83+
84+
The Python 3 script uses no extra dependencies so you can run the script out-of-the-box on any system that has Python installed (popular Linux distros and Macs for example have it by default).
85+
86+
87+
<a name="cp"></a>
88+
## Changing SublimeNotebook password
89+
90+
To change password of your Sublime Notebook, decrypt your existing notes using old `manager.py`, then exit the script in decrypted state (using "d").
91+
92+
Then start `manager.py` again to re-encrypt your notes. This time you will be asked for a new password to encrypt your notes.
93+
94+
95+
<a name="custen"></a>
96+
## Customizing which folders are encrypted
97+
98+
To customize which folders are encrypted, use the `settings.json` file in `sublime_notebook/` directory.
99+
100+
1. "private_folders" are the one that are encrypted.
101+
2. "public_folders" are not encrypted.
102+
103+
A folder by default is public if it is not included in either of them.
104+
105+
You can also use the "*" symbol to select all folders. For example, in the following `settings.json` file, all folders except "web_links" are private(encrypted).
106+
107+
```json
108+
{
109+
"private_folders": [
110+
"*"
111+
],
112+
"public_folders": [
113+
"web_links"
114+
]
115+
}
116+
```
117+
118+
**NOTE** - You should edit `settings.json` file only when the notebook is in a decrypted state. Changing it when notebook is encrypted can cause
119+
unintentional side-effects. `"is_encrypted": false` will be present in `settings.json` when notebook is decrypted.
120+
121+
122+
<a name="git"></a>
123+
## Automatic git backups
124+
125+
> This feature comes in handy for those who don't trust cloud data storage providers. You can even use this as a second backup for your data. I personally have auto git backups set up so that my notes are stored on both Dropbox and GitHub.
126+
127+
To enable git backups, enable the feature from `sublime_notebook/settings.json`.
128+
129+
```json
130+
{
131+
"do_git_backup": true,
132+
}
133+
```
134+
135+
Once this setting is enabled, you will have to make your notebook a git repository and set `notebookbackup` branch to the git remote you want to backup to.
136+
Start with an empty remote repository to avoid any conflicts.
137+
138+
```sh
139+
# pwd is the directory with manager.py and sublime_notebook/ folder.
140+
$ git init
141+
$ git remote add notebookbackup <GIT_REMOTE_URL>
142+
# ^ ssh git url preferred
143+
```
144+
145+
The git backup will run when you re-encrypt after decrypting the notebook.
146+
147+
![git push](https://i.imgur.com/NFHZcv0.png)
148+
149+
To change how frequently git backup happens, change the `git_push_interval_minutes` value in `settings.json`.
150+
151+
```js
152+
{
153+
"git_push_interval_minutes": 1440,
154+
}
155+
```
156+
157+
1440 minutes means 24 hours i.e. 1 day. Set it to `0` to enable instant backups.
158+
159+
160+
<a name="mdext"></a>
161+
## Setting up better Markdown highlighting in Sublime Text
162+
163+
* Install the packages from here.
164+
165+
* [Sublime Markdown Extended](https://github.com/jonschlinkert/sublime-markdown-extended)
166+
* [Sublime Monokai Extended](https://github.com/jonschlinkert/sublime-monokai-extended) - companion to the first package.
167+
168+
* Make Sublime Markdown Extended as default language for markdown.
169+
170+
> Navigate through the following menus in Sublime Text: View -> Syntax -> Open all with current extension as... -> Markdown Extended
171+
172+
* Make Sublime Monokai Extended default theme for Markdown extended. Open `Settings - Syntax Specific` from preferences and update the file as follows.
173+
174+
```js
175+
{
176+
"color_scheme": "Packages/Monokai Extended/Monokai Extended.tmTheme",
177+
"extensions":
178+
[
179+
"md"
180+
]
181+
}
182+
```
183+
184+
185+
<a name="faq"></a>
186+
## FAQ
187+
188+
Only *.txt and *.md files are detected as notes.
189+
190+
You don't need to be in decrypted state to create a new note. Even when in encrypted state, you can create a note.
191+
When manager.py starts decrypting the notes, this new file will be ignored and will be encrypted when it's time to encrypt.

sublime_notebook/message.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""
2+
Print statements
3+
"""
4+
5+
def print_info(msg):
6+
print('\n[[ ' + msg + ' ]]\n')
7+
8+
def print_err(msg):
9+
print('\n<< ' + msg + ' >>\n')
10+

0 commit comments

Comments
 (0)