mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
create config file and ask for journal file name
with autocomplete !!!
This commit is contained in:
parent
04cc68a29a
commit
1569f9c59c
1 changed files with 25 additions and 5 deletions
30
jrnl.py
30
jrnl.py
|
@ -11,10 +11,12 @@ from datetime import datetime
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
import readline, glob
|
||||||
|
|
||||||
config = {
|
|
||||||
'journal': "/Users/dedan/Dropbox/Notes/journal_neu.txt",
|
default_config = {
|
||||||
'editor': "subl -w",
|
'journal': os.path.expanduser("~/journal.txt"),
|
||||||
|
'editor': "",
|
||||||
'default_hour': 9,
|
'default_hour': 9,
|
||||||
'default_minute': 0,
|
'default_minute': 0,
|
||||||
'timeformat': "%Y-%m-%d %H:%M",
|
'timeformat': "%Y-%m-%d %H:%M",
|
||||||
|
@ -202,7 +204,26 @@ class Journal:
|
||||||
self.sort()
|
self.sort()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print sys.argv
|
config_path = os.path.expanduser('~/.jrnl_config')
|
||||||
|
if not os.path.exists(config_path):
|
||||||
|
def autocomplete(text, state):
|
||||||
|
expansions = glob.glob(os.path.expanduser(text)+'*')
|
||||||
|
expansions = [e+"/" if os.path.isdir(e) else e for e in expansions]
|
||||||
|
expansions.append(None)
|
||||||
|
return expansions[state]
|
||||||
|
readline.set_completer_delims(' \t\n;')
|
||||||
|
readline.parse_and_bind("tab: complete")
|
||||||
|
readline.set_completer(autocomplete)
|
||||||
|
|
||||||
|
path_query = 'Path to your journal file (leave blank for ~/journal.txt): '
|
||||||
|
journal_path = raw_input(path_query).strip() or os.path.expanduser('~/journal.txt')
|
||||||
|
default_config['journal'] = os.path.expanduser(journal_path)
|
||||||
|
open(default_config['journal'], 'a').close() # Touch to make sure it's there
|
||||||
|
with open(config_path, 'w') as f:
|
||||||
|
json.dump(default_config, f)
|
||||||
|
with open(config_path) as f:
|
||||||
|
config = json.load(f)
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
composing = parser.add_argument_group('Composing', 'Will make an entry out of whatever follows as arguments')
|
composing = parser.add_argument_group('Composing', 'Will make an entry out of whatever follows as arguments')
|
||||||
composing.add_argument('-date', dest='date', help='Date, e.g. "yesterday at 5pm"')
|
composing.add_argument('-date', dest='date', help='Date, e.g. "yesterday at 5pm"')
|
||||||
|
@ -215,7 +236,6 @@ if __name__ == "__main__":
|
||||||
reading.add_argument('-n', dest='limit', default=None, metavar="N", help='Shows the last n entries matching the filter', nargs="?", type=int)
|
reading.add_argument('-n', dest='limit', default=None, metavar="N", help='Shows the last n entries matching the filter', nargs="?", type=int)
|
||||||
reading.add_argument('-json', dest='json', action="store_true", help='Returns a JSON-encoded version of the Journal')
|
reading.add_argument('-json', dest='json', action="store_true", help='Returns a JSON-encoded version of the Journal')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
print args
|
|
||||||
|
|
||||||
# open journal
|
# open journal
|
||||||
journal = Journal(config=config)
|
journal = Journal(config=config)
|
||||||
|
|
Loading…
Add table
Reference in a new issue