mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-05-01 04:30:37 +02:00
Add lein aliases plugin that shows aliases from project.clj in autosuggestions
This commit is contained in:
parent
d2725d44fc
commit
9c9b02bcc2
2 changed files with 70 additions and 0 deletions
37
plugins/lein-aliases/lein-aliases.py
Executable file
37
plugins/lein-aliases/lein-aliases.py
Executable 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='')
|
||||
Loading…
Add table
Add a link
Reference in a new issue