diff --git a/modules/vim/module.py b/modules/vim/module.py index 83df53d..3b6bf36 100644 --- a/modules/vim/module.py +++ b/modules/vim/module.py @@ -1,5 +1,6 @@ from AbstractModule import AbstractModule from subprocess import call +from PyInquirer import prompt import os import shutil @@ -7,36 +8,39 @@ import shutil class VimModule(AbstractModule): def __init__(self): super().__init__() + self.plugins = { + "Colorschemes": "Plug 'https://github.com/rafi/awesome-vim-colorschemes.git'", + "Unix Operations": "Plug 'https://github.com/tpope/vim-eunuch.git'", + "Emmet": "Plug 'https://github.com/mattn/emmet-vim.git'", + "Meta5 Theme": "Plug 'https://github.com/christophermca/meta5.git'", + "Nerdtree": "Plug 'https://github.com/scrooloose/nerdtree'", + "Lightline": "Plug 'https://github.com/itchyny/lightline.vim'" + } + + def do_module_selection(self): + mapped_list = [] + for choice in self.plugins.keys(): + mapped_list.append({ + "name": choice + }) + + print("Available Plugins:") + module_selection = [ + { + 'type': 'checkbox', + 'message': 'Select plugins', + 'name': 'modules', + 'choices': mapped_list + } + ] + return prompt(module_selection) def run(self): - plugins = [ - ("1. Colorschemes", "Plug 'https://github.com/rafi/awesome-vim-colorschemes.git'"), - ("2. Unix Operations", "Plug 'https://github.com/tpope/vim-eunuch.git'"), - ("3. Emmet", "Plug 'https://github.com/mattn/emmet-vim.git'"), - ("4. Meta5 Theme", "Plug 'https://github.com/christophermca/meta5.git'"), - ("5. Nerdtree", "Plug 'https://github.com/scrooloose/nerdtree'"), - ("6. Lightline", "Plug 'https://github.com/itchyny/lightline.vim'") - ] - - print("Available Plugins:\n") - - for key in plugins: - print(key[0]) - - print("") - - # Select Plugins - user_input = [int(userInput) for userInput in input("Select modules: ").split()] - clean_plugin_list = set(user_input) + selected_modules = self.do_module_selection()['modules'] # print out selected plugins - for element in clean_plugin_list: - selection = element - 1 - try: - print(plugins[selection][0]) - except Exception: - print("Fail") + [print(x) for x in selected_modules] # Create vimrc file vimrc_exists = os.path.isfile("testfile") @@ -46,9 +50,8 @@ class VimModule(AbstractModule): with open("testfile", "r") as vimrc_out_file: for line in vimrc_out_file: if line.startswith("call plug#begin('~/.vim/plugged')"): - for element in clean_plugin_list: - selection = element - 1 - line = line.strip() + "\n" + plugins[selection][1] + "\n" + for element in selected_modules: + line = line.strip() + "\n" + self.plugins[element] + "\n" temp_file.write(line) temp_file.close() shutil.move('temp', 'testfile') @@ -60,9 +63,8 @@ class VimModule(AbstractModule): else: with open("testfile", "w+") as vimrc_file: vimrc_file.write("\n" + "call plug#begin('~/.vim/plugged')\n") - for element in clean_plugin_list: - selection = element - 1 - vimrc_file.write(plugins[selection][1] + "\n") + for element in selected_modules: + vimrc_file.write(self.plugins[element] + "\n") vimrc_file.write("call plug#end()\n") vimdir_exists = os.path.isdir("/home/clay/Gitlab/linux-tools/testdirectory/")