Skip to content

Instantly share code, notes, and snippets.

@Saakshaat
Last active June 29, 2020 08:24
Show Gist options
  • Save Saakshaat/d99395af8f731d17198c9d7c7bc77215 to your computer and use it in GitHub Desktop.
Save Saakshaat/d99395af8f731d17198c9d7c7bc77215 to your computer and use it in GitHub Desktop.
Terminal Notes

Terminal

Terminal's every developer's best friend; I use mine terminal for almost everything, writing/executing custom scripts, restarting Spotify, opening different IDEs/Editors and what not.

When a new session pops up, my main focus is make minimal efforts and optimise productivity, which, for me is driven by streamlining my priorites and deliverables.

Thus, I had to find a way to combine my terminal and notes/TODOs, and here we are.

Setup

Application

First, you have to install and signup on the Simplenote app on your mobile. This will act as the end client for saving your notes.

Dependency

Our script makes calls to the simplenote API, so we have to install this: sudo pip install simplenote # using python's package manager since we'll be using this in a python script or sudo easy_install simplenote Both of these need root permissions, so don't shy from providing your device's password on prompt 🤔 🤭

Files

For MacOS, you'd have to create an executable file in /usr/local/bin/

Open a new terminal session and change directory to /usr/local/bin/ using your relative path. For me this was

cd ../../ # going back 2 levels
cd /usr/local/bin
# this could be shortened to cd ../../usr/local/bin

Now, you must create a file to execute the script in: touch note This will create a file called note in the current directory.

To edit this, you can open it in an editor of your choice. For me, this was VSCode: code note

Script

Now paste the script below into your file. Remember to replace the email and password parameters with your credentials from the app.

Now, let's make this script executable: chmod +x /usr/local/bin/note

Use

This script runs using 3 types of parameters:

Default

This only contains the note's content: note 'this is the note content'

Note, if you've named your file something else, replace note with your filename (the script would only run if the filename is met).

With Tag

This contains a custom tag wherewithal the note's content: note github 'remember to upload this gist'

Simplenote can also tag certain notes; this would help you organize and find your notes through tagging. If there are 3 arguments, the second argument is parsed as a tag.

If a tag is not provided, the default tag is 'terminal'. You can change this in Lines 15 and 37.

With Tag and Header

note github Terminal_Notes "I need to upload everything about the notes from terminal thing from the setup to use"

Simplenote saves the first content as a header. If the script call is provided with 4 arguments, it parses the second as the tag, third as header and the fourth as content.

The default header is 'TODOs'

All headers are prefixed with the date.

Output

Simplenote saves the header on top with the date, tags your note with the day and the tag provided. Each note is stamped with the time of submission.

Inspiration/Source

The original code and method was described by Matt Dziuban in his BOSTINNO post I've only made small additions to their script and the original idea is to be accredited to them.

#!/usr/bin/env python
import sys
import datetime
from simplenote import Simplenote
import itertools
import threading
import time
import sys
from datetime import datetime
now = datetime.now()
done = False
# Replace the login and password with your credentials
simplenote = Simplenote('login@email.com', 'PASSWORD')
today = now.strftime("%m/%d/%Y")
day = now.strftime("%A")
time = now.strftime("%H:%M:%S")
def create_note(message, tag = ['terminal'], header='TODOs'):
note = {
'tags': [day, tag],
'content': today+" {} \n {} - ".format(header, time) + message
}
simplenote.add_note(note)
def write_to_note(note, message):
note = simplenote.get_note(note['key'])[0]
note['content'] = note['content']+"\n {} - ".format(time)+message
simplenote.update_note(note)
def get_notes():
return simplenote.get_note_list()[0]
"""
Animation authored by Andrew Clark: https://stackoverflow.com/users/505154/andrew-clark
S/O Post: https://stackoverflow.com/questions/22029562/python-how-to-make-simple-animated-loading-while-process-is-running
"""
def animate():
for c in itertools.cycle(['|', '/', '-', '\\']):
if done:
break
sys.stdout.write('\rSending Note ' + c)
sys.stdout.flush()
import time as t
t.sleep(0.1)
sys.stdout.write("\nDone " + u'\U00002714' + '\n')
t = threading.Thread(target=animate)
t.start()
def main():
if len(sys.argv) == 1:
print('You must specify a message')
return
if len(sys.argv) == 2:
message = sys.argv[1]
for note in get_notes():
if day in note['tags'] and 'terminal'in note['tags']:
return write_to_note(note, message)
create_note(message)
if len(sys.argv) == 3:
message = sys.argv[2]
tag = sys.argv[1]
for note in get_notes():
if day in note['tags'] and tag in note['tags']:
return write_to_note(note, message)
create_note(message, tag)
if len(sys.argv) == 4:
message = sys.argv[3]
header = sys.argv[2]
tag = sys.argv[1]
for note in get_notes():
if day in note['tags'] and tag in note['tags'] and header in note['content']:
return write_to_note(note, message)
create_note(message, tag, header)
if __name__=='__main__':
main()
done = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment