#!/usr/bin/python

import sys, os

def file_len(fname):
    with open(fname) as f:
    	i = -1
        for i, l in enumerate(f):
            pass
    return i + 1

note_flag = False
note = ""
fn = os.path.join(os.path.dirname(__file__), 'nbref.txt')

if len(sys.argv) > 1:
	#look for command flags
	for arg in sys.argv:
		if note_flag == True:
			note = arg
			note_flag = False
			continue
		if arg == '-n':
			note_flag = True
			continue
	#add to the notebook file
	file_index = file_len(fn)
	with open(fn, "a") as myfile:
		myfile.write(str(file_index) + ". " + sys.argv[1])
		if note:
			myfile.write("  |  note: " + note)
		myfile.write("\n")
	#print receipt
	print file_index
else:
	print 'No argument passed'