Merge pull request #39 from maebert/multiple-journals

Multiple journals
This commit is contained in:
Manuel Ebert 2012-06-16 10:51:56 -07:00
commit 1903749901
4 changed files with 38 additions and 5 deletions

View file

@ -4,6 +4,7 @@ Changelog
* [Improved] Supports deleting of last entry. * [Improved] Supports deleting of last entry.
* [Fixed] Fixes a bug where --encrypt or --decrypt without a target file would not work. * [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 a config option for setting word wrap.
* [Improved] Supports multiple journal files.
### 0.3.0 (May 24, 2012) ### 0.3.0 (May 24, 2012)

View file

@ -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. 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). - `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. - `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. - `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. > 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 ### JSON export
Can do: Can do:

View file

@ -17,7 +17,9 @@ def module_exists(module_name):
return True return True
default_config = { default_config = {
'journal': os.path.expanduser("~/journal.txt"), 'journals': {
"default": os.path.expanduser("~/journal.txt")
},
'editor': "", 'editor': "",
'encrypt': False, 'encrypt': False,
'password': "", 'password': "",
@ -43,7 +45,7 @@ def install_jrnl(config_path='~/.jrnl_config'):
# Where to create the journal? # Where to create the journal?
path_query = 'Path to your journal file (leave blank for ~/journal.txt): ' 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') 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? # Encrypt it?
if module_exists("Crypto"): 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.") print("clint not found. To turn on highlighting, install clint and set highlight to true in your .jrnl_conf.")
default_config['highlight'] = False 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 # Write config to ~/.jrnl_conf
with open(config_path, 'w') as f: with open(config_path, 'w') as f:

View file

@ -36,6 +36,7 @@ def update_config(config):
config[key] = default_config[key] config[key] = default_config[key]
with open(CONFIG_PATH, 'w') as f: with open(CONFIG_PATH, 'w') as f:
json.dump(config, f, indent=2) json.dump(config, f, indent=2)
print("[.jrnl_conf updated to newest version]")
def parse_args(): def parse_args():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
@ -128,6 +129,14 @@ def print_tags(journal):
for n, tag in sorted(tag_counts, reverse=True): for n, tag in sorted(tag_counts, reverse=True):
print("{:20} : {}".format(tag, n)) 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(): def cli():
if not os.path.exists(CONFIG_PATH): if not os.path.exists(CONFIG_PATH):
config = install_jrnl(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.") 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) 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) mode_compose, mode_export = guess_mode(args, config)
# open journal file # open journal file