from IModule import IModule from subprocess import call import os import shutil class VimModule(IModule): def __init__(self): super().__init__() def get_command(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) # print out selected plugins for element in clean_plugin_list: selection = element - 1 try: print(plugins[selection][0]) except Exception: print("Fail") # Create vimrc file vimrc_exists = os.path.isfile("testfile") if vimrc_exists: temp_file = open('temp', 'w') 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" temp_file.write(line) temp_file.close() shutil.move('temp', 'testfile') sorted_file = "awk -i inplace ' !x[$0]++' ~/Gitlab/linux-tools/testfile" call(sorted_file, shell=True) 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") vimrc_file.write("call plug#end()\n") vimdir_exists = os.path.isdir("/home/clay/Gitlab/linux-tools/testdirectory/") if vimdir_exists: install_vimplug = "cd ~/Gitlab/linux-tools/testdirectory/ && mkdir autoload && cd autoload && touch test.txt" call(install_vimplug, shell=True) else: make_vimdir = "cd ~/Gitlab/linux-tools/ && mkdir testdirectory && cd testdirectory && mkdir autoload && cd autoload && touch test.txt" call(make_vimdir, shell=True)