Skip to content

Commit

Permalink
Add feature for selecting custom author name or system username
Browse files Browse the repository at this point in the history
  • Loading branch information
mjerrar committed Dec 10, 2018
1 parent a3726f4 commit 86bc7b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Licence Snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,20 @@ def get_snippet_dir():
return SNIPPETS_DIR


def get_snippet_vars():
def get_snippet_vars(settings):
# Mapping of additional snippet variable names to their values. If the value is
# callable, it is called on snippet insertion to compute actual value.
use_name = settings.get('use_name', 'system')
if use_name == 'system':
author_name = getuser() # TM_FULLNAME doesn't seem to be supported.
elif use_name == 'author':
author_name = settings.get('author_name', 'add "author_name": "your_name" in preferences->settings(user)')
else:
raise ValueError('Invalid value for use_name setting')

SNIPPET_VARS = {
'YEAR': date.today().year, # TM_YEAR doesn't seem to be supported.
'USER': getuser() # TM_FULLNAME doesn't seem to be supported.
'USER': author_name
}
return SNIPPET_VARS

Expand Down Expand Up @@ -90,7 +98,7 @@ def run(self, edit, name):
raise ValueError('Invalid value for licence_wrap_lines setting')

args = {'contents': load_snippet(name)}
for key, value in get_snippet_vars().items():
for key, value in get_snippet_vars(settings).items():
if isinstance(value, Callable):
value = value()
args[key] = str(value) if ST3 else unicode(value)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ for the setting you want to change.

- *licence_comment_style* = *none*, *line*, or *block* (default: *line*)
- *licence_wrap_lines* = *True* or *False* (default: *False*)

You can switch between system user name and your custom author name.
- *use_name* = *system* or *author* (default: *system*)
- *author_name* = *your_name_here* (default: *add "author_name": "your_name" in preferences->settings(user)*)

0 comments on commit 86bc7b1

Please sign in to comment.