diff --git a/CHANGELOG.md b/CHANGELOG.md index 10e77795..101dbc11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog * [Improved] Supports deleting of last entry. * [Fixed] Fixes a bug where --encrypt or --decrypt without a target file would not work. * [Improved] Supports a config option for setting word wrap. +* [Improved] Supports multiple journal files. ### 0.3.0 (May 24, 2012) diff --git a/README.md b/README.md index 0515f4ab..115fef5d 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ The first time launched, _jrnl_ will create a file called `.jrnl_config` in your The configuration file is a simple JSON file with the following options. - - `journal`: path to your journal file + - `journals`: path to your journal files - `editor`: if set, executes this command to launch an external editor for writing your entries, e.g. `vim` or `subl -w` (note the `-w` flag to make sure _jrnl_ waits for Sublime Text to close the file before writing into the journal). - `encrypt`: if `true`, encrypts your journal using AES. - `password`: you may store the password you used to encrypt your journal in plaintext here. This is useful if your journal file lives in an unsecure space (ie. your Dropbox), but the config file itself is more or less safe. @@ -117,6 +117,17 @@ The configuration file is a simple JSON file with the following options. > > Or use the built-in prompt or an external editor to compose your entries. +### Multiple journal files + +You can configure _jrnl_ to use with multiple journals (eg. `private` and `work`) by defining more journals in your `.jrnl_config`, for example: + + "journals": { + "default": "~/journal.txt", + "work": "~/work.txt" + }, + +The `default` journal gets created the first time you start _jrnl_. Now you can access the `work` journal by using `jrnl work` instead of `jrnl`, eg. `jrnl work at 10am: Meeting with @Steve" or `jrnl work -n 3` will use `~/work.txt`, while `jrnl -n 3` will display the last three entries from `~/journal.txt` (and so does `jrnl default -n 3`). + ### JSON export Can do: diff --git a/jrnl/install.py b/jrnl/install.py index 49f58e31..7341f8bb 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -17,7 +17,9 @@ def module_exists(module_name): return True default_config = { - 'journal': os.path.expanduser("~/journal.txt"), + 'journals': { + "default": os.path.expanduser("~/journal.txt") + }, 'editor': "", 'encrypt': False, 'password': "", @@ -43,7 +45,7 @@ def install_jrnl(config_path='~/.jrnl_config'): # Where to create the journal? 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) + default_config['journals']['default'] = os.path.expanduser(journal_path) # Encrypt it? if module_exists("Crypto"): @@ -61,7 +63,7 @@ def install_jrnl(config_path='~/.jrnl_config'): print("clint not found. To turn on highlighting, install clint and set highlight to true in your .jrnl_conf.") default_config['highlight'] = False - open(default_config['journal'], 'a').close() # Touch to make sure it's there + open(default_config['journals']['default'], 'a').close() # Touch to make sure it's there # Write config to ~/.jrnl_conf with open(config_path, 'w') as f: diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index 811cd222..0e2d7af1 100755 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -36,6 +36,7 @@ def update_config(config): config[key] = default_config[key] with open(CONFIG_PATH, 'w') as f: json.dump(config, f, indent=2) + print("[.jrnl_conf updated to newest version]") def parse_args(): parser = argparse.ArgumentParser() @@ -128,6 +129,14 @@ def print_tags(journal): for n, tag in sorted(tag_counts, reverse=True): print("{:20} : {}".format(tag, n)) + +def touch_journal(filename): + """If filename does not exist, touch the file""" + if not os.path.exists(filename): + print("[Journal created at {}".format(filename)) + open(filename, 'a').close() + + def cli(): if not os.path.exists(CONFIG_PATH): config = install_jrnl(CONFIG_PATH) @@ -141,7 +150,17 @@ def cli(): print("According to your jrnl_conf, your journal is encrypted, however PyCrypto was not found. To open your journal, install the PyCrypto package from http://www.pycrypto.org.") sys.exit(-1) - args = parse_args() + args = parse_args() + + # If the first textual argument points to a journal file, + # use this! + if args.text and args.text[0] in config['journals']: + config['journal'] = config['journals'].get(args.text[0]) + args.text = args.text[1:] + else: + config['journal'] = config['journals'].get('default') + + touch_journal(config['journal']) mode_compose, mode_export = guess_mode(args, config) # open journal file