Split functionality into functions
This commit is contained in:
parent
33ae820b94
commit
ad900097dc
@ -22,13 +22,17 @@ class VimModule(AbstractModule):
|
||||
self.plugins = self.json_config['plugins']
|
||||
self.settings = self.json_config['settings']
|
||||
|
||||
def do_plugin_selection(self):
|
||||
def create_folder_structure(self):
|
||||
# Create necessary folder structure for vim
|
||||
os.makedirs(str(get_vim_root().joinpath("autoload")), exist_ok=True)
|
||||
os.makedirs(str(get_vim_root().joinpath("plugged")), exist_ok=True)
|
||||
|
||||
def create_plugin_section(self, vimrc_content):
|
||||
mapped_list = []
|
||||
for choice in self.plugins.keys():
|
||||
mapped_list.append({
|
||||
"name": choice
|
||||
})
|
||||
|
||||
print("Available Plugins:")
|
||||
module_selection = [
|
||||
{
|
||||
@ -38,29 +42,9 @@ class VimModule(AbstractModule):
|
||||
'choices': mapped_list
|
||||
}
|
||||
]
|
||||
return prompt(module_selection)['modules']
|
||||
|
||||
def run(self):
|
||||
|
||||
# Create necessary folder structure for vim
|
||||
os.makedirs(str(get_vim_root().joinpath("autoload")), exist_ok=True)
|
||||
os.makedirs(str(get_vim_root().joinpath("plugged")), exist_ok=True)
|
||||
|
||||
selected_plugins = self.do_plugin_selection()
|
||||
default_settings = list(self.settings.values())
|
||||
# print out selected plugins
|
||||
selected_plugins = prompt(module_selection)['modules']
|
||||
print("\033[4mYour selection:\033[0m")
|
||||
[print(x) for x in selected_plugins]
|
||||
print("\n\033[4mDefault settings:\033[0m")
|
||||
[print(i) for i in default_settings]
|
||||
|
||||
# Create vimrc file
|
||||
vimrc_path = str(get_vim_root().joinpath(".vimrc"))
|
||||
try:
|
||||
with open(vimrc_path, "r") as vimrc_file:
|
||||
vimrc_content = vimrc_file.readlines()
|
||||
except FileNotFoundError:
|
||||
vimrc_content = []
|
||||
|
||||
try:
|
||||
index = vimrc_content.index("call plug#begin('~/.vim/plugged')\n") + 1
|
||||
@ -73,17 +57,42 @@ class VimModule(AbstractModule):
|
||||
vimrc_content.append(self.plugins[element] + "\n")
|
||||
vimrc_content.append("call plug#end()\n")
|
||||
|
||||
def create_setting_section(self, vimrc_content):
|
||||
default_settings = list(self.settings.values())
|
||||
print("\n\033[4mDefault settings:\033[0m")
|
||||
[print(i) for i in default_settings]
|
||||
|
||||
default_settings.reverse()
|
||||
for setting in default_settings:
|
||||
vimrc_content.insert(0, setting + "\n")
|
||||
|
||||
def get_vimfile_working_copy(self):
|
||||
vimrc_path = str(get_vim_root().joinpath(".vimrc"))
|
||||
try:
|
||||
with open(vimrc_path, "r") as vimrc_file:
|
||||
vimrc_content = vimrc_file.readlines()
|
||||
except FileNotFoundError:
|
||||
vimrc_content = []
|
||||
|
||||
return vimrc_content
|
||||
|
||||
def write_vimfile(self, vimrc_content):
|
||||
seen = set()
|
||||
seen_add = seen.add
|
||||
vimrc_content = [x1 for x1 in vimrc_content if not (x1 in seen or seen_add(x1))]
|
||||
|
||||
vimrc_path = str(get_vim_root().joinpath(".vimrc"))
|
||||
with open(vimrc_path, "w") as vimrc_file:
|
||||
for line in vimrc_content:
|
||||
vimrc_file.write(line)
|
||||
|
||||
def run(self):
|
||||
|
||||
self.create_folder_structure()
|
||||
vimrc_content = self.get_vimfile_working_copy()
|
||||
self.create_plugin_section(vimrc_content)
|
||||
self.create_setting_section(vimrc_content)
|
||||
self.write_vimfile(vimrc_content)
|
||||
|
||||
# TODO: check if existing plugin manager file
|
||||
# TODO: else download plugin manager
|
||||
|
Loading…
Reference in New Issue
Block a user