diff --git a/jrnl/Journal.py b/jrnl/Journal.py index af9e6b9e..9b568ee4 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -313,12 +313,6 @@ def open_journal(name, config, legacy=False): backwards compatibility with jrnl 1.x """ config = config.copy() - journal_conf = config['journals'].get(name) - if type(journal_conf) is dict: # We can override the default config on a by-journal basis - log.debug('Updating configuration with specific journal overrides %s', journal_conf) - config.update(journal_conf) - else: # But also just give them a string to point to the journal file - config['journal'] = journal_conf config['journal'] = os.path.expanduser(os.path.expandvars(config['journal'])) if os.path.isdir(config['journal']): diff --git a/jrnl/cli.py b/jrnl/cli.py index 5c4585ce..e6a1e3ec 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -153,6 +153,7 @@ def run(manual_args=None): # If the first textual argument points to a journal file, # use this! journal_name = args.text[0] if (args.text and args.text[0] in config['journals']) else 'default' + if journal_name is not 'default': args.text = args.text[1:] elif "default" not in config['journals']: @@ -160,6 +161,8 @@ def run(manual_args=None): util.prompt(list_journals(config)) sys.exit(1) + config = util.scope_config(config, journal_name) + # If the first remaining argument looks like e.g. '-3', interpret that as a limiter if not args.limit and args.text and args.text[0].startswith("-"): try: @@ -182,7 +185,14 @@ def run(manual_args=None): # Piping data into jrnl raw = util.py23_read() elif config['editor']: - raw = util.get_text_from_editor(config) + template = "" + if config['template']: + try: + template = open(config['template']).read() + except: + util.prompt("[Could not read template at '']".format(config['template'])) + sys.exit(1) + raw = util.get_text_from_editor(config, template) else: try: raw = util.py23_read("[Compose Entry; " + _exit_multiline_code + " to finish writing]\n") diff --git a/jrnl/install.py b/jrnl/install.py index bee35924..2426aea6 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -47,6 +47,7 @@ default_config = { }, 'editor': os.getenv('VISUAL') or os.getenv('EDITOR') or "", 'encrypt': False, + 'template': False, 'default_hour': 9, 'default_minute': 0, 'timeformat': "%Y-%m-%d %H:%M", diff --git a/jrnl/upgrade.py b/jrnl/upgrade.py index c73fa086..88c9545a 100644 --- a/jrnl/upgrade.py +++ b/jrnl/upgrade.py @@ -82,7 +82,7 @@ older versions of jrnl anymore. for journal_name, path in encrypted_journals.items(): util.prompt("\nUpgrading encrypted '{}' journal stored in {}...".format(journal_name, path)) backup(path, binary=True) - old_journal = Journal.open_journal(journal_name, config, legacy=True) + old_journal = Journal.open_journal(journal_name, util.scope_config(config, journal_name), legacy=True) new_journal = EncryptedJournal.from_journal(old_journal) new_journal.write() util.prompt(" Done.") @@ -90,7 +90,7 @@ older versions of jrnl anymore. for journal_name, path in plain_journals.items(): util.prompt("\nUpgrading plain text '{}' journal stored in {}...".format(journal_name, path)) backup(path) - old_journal = Journal.open_journal(journal_name, config, legacy=True) + old_journal = Journal.open_journal(journal_name, util.scope_config(config, journal_name), legacy=True) new_journal = Journal.PlainJournal.from_journal(old_journal) new_journal.write() util.prompt(" Done.") diff --git a/jrnl/util.py b/jrnl/util.py index 7f8caaa1..f93d8fd8 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -13,6 +13,9 @@ import subprocess import codecs import unicodedata import shlex +import logging + +log = logging.getLogger(__name__) PY3 = sys.version_info[0] == 3 @@ -122,6 +125,20 @@ def load_config(config_path): return yaml.load(f) +def scope_config(config, journal_name): + if journal_name not in config['journals']: + return config + config = config.copy() + journal_conf = config['journals'].get(journal_name) + if type(journal_conf) is dict: # We can override the default config on a by-journal basis + log.debug('Updating configuration with specific journal overrides %s', journal_conf) + config.update(journal_conf) + else: # But also just give them a string to point to the journal file + config['journal'] = journal_conf + config.pop('journals') + return config + + def get_text_from_editor(config, template=""): filehandle, tmpfile = tempfile.mkstemp(prefix="jrnl", text=True, suffix=".txt") with codecs.open(tmpfile, 'w', "utf-8") as f: