Add lein aliases plugin that shows aliases from project.clj in autosuggestions

This commit is contained in:
Ari Paasonen 2017-01-15 21:17:27 +02:00
commit 9c9b02bcc2
2 changed files with 70 additions and 0 deletions

View file

@ -0,0 +1,37 @@
#!/usr/bin/env python
from __future__ import print_function
import re
def readFile(filename):
try:
proj = open(filename, 'r')
content = proj.read()
proj.close()
return content
except IOError as e:
print('', end='')
def parse_key_and_values(raw):
no_double_quotes = raw.replace('"', '')
no_last_bracket = re.sub(r']\s*$','', no_double_quotes)
key_value_strings = no_last_bracket.split(']')
return map(key_value_string_to_pair, key_value_strings)
def key_value_string_to_pair(key_value_str):
key_and_value = key_value_str.split('[')
return key_and_value[0].strip() + ":ALIAS: " + key_and_value[1]
def read_aliases(filename):
keys_and_commands = re.search('(?<=:aliases {").*?(?=})', readFile(filename).replace('\n', ''))
if keys_and_commands is None:
print('Not found!')
return []
else:
keys_and_commands_raw = keys_and_commands.group(0)
return parse_key_and_values(keys_and_commands_raw)
aliases_from_project = read_aliases('project.clj')
out = ';'.join(aliases_from_project)
print(out, end='')