2019-12-22 02:45:19 +01:00
|
|
|
from AbstractModule import AbstractModule
|
2019-12-16 12:08:22 +01:00
|
|
|
from subprocess import call
|
2019-12-22 03:59:38 +01:00
|
|
|
from PyInquirer import prompt
|
2019-12-16 12:08:22 +01:00
|
|
|
import os
|
|
|
|
import shutil
|
2019-12-14 04:48:57 +01:00
|
|
|
|
2019-12-22 02:45:19 +01:00
|
|
|
|
|
|
|
class VimModule(AbstractModule):
|
2019-12-14 04:22:34 +01:00
|
|
|
def __init__(self):
|
2019-12-14 05:47:33 +01:00
|
|
|
super().__init__()
|
2019-12-22 03:59:38 +01:00
|
|
|
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
|
|
|
|
}
|
2019-12-14 04:22:34 +01:00
|
|
|
]
|
2019-12-22 03:59:38 +01:00
|
|
|
return prompt(module_selection)
|
2019-12-14 04:22:34 +01:00
|
|
|
|
2019-12-22 03:59:38 +01:00
|
|
|
def run(self):
|
2019-12-14 04:22:34 +01:00
|
|
|
|
2019-12-22 03:59:38 +01:00
|
|
|
selected_modules = self.do_module_selection()['modules']
|
2019-12-15 07:30:20 +01:00
|
|
|
|
|
|
|
# print out selected plugins
|
2019-12-22 03:59:38 +01:00
|
|
|
[print(x) for x in selected_modules]
|
2019-12-15 07:30:20 +01:00
|
|
|
|
|
|
|
# Create vimrc file
|
|
|
|
vimrc_exists = os.path.isfile("testfile")
|
|
|
|
|
|
|
|
if vimrc_exists:
|
2019-12-16 12:11:30 +01:00
|
|
|
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')"):
|
2019-12-22 03:59:38 +01:00
|
|
|
for element in selected_modules:
|
|
|
|
line = line.strip() + "\n" + self.plugins[element] + "\n"
|
2019-12-16 12:11:30 +01:00
|
|
|
temp_file.write(line)
|
|
|
|
temp_file.close()
|
|
|
|
shutil.move('temp', 'testfile')
|
2019-12-19 14:03:31 +01:00
|
|
|
|
|
|
|
# Merge duplicates to first ocassion with awk
|
2019-12-16 12:11:30 +01:00
|
|
|
sorted_file = "awk -i inplace ' !x[$0]++' ~/Gitlab/linux-tools/testfile"
|
|
|
|
call(sorted_file, shell=True)
|
2019-12-15 07:30:20 +01:00
|
|
|
|
|
|
|
else:
|
2019-12-16 12:10:08 +01:00
|
|
|
with open("testfile", "w+") as vimrc_file:
|
|
|
|
vimrc_file.write("\n" + "call plug#begin('~/.vim/plugged')\n")
|
2019-12-22 03:59:38 +01:00
|
|
|
for element in selected_modules:
|
|
|
|
vimrc_file.write(self.plugins[element] + "\n")
|
2019-12-17 23:36:42 +01:00
|
|
|
vimrc_file.write("call plug#end()\n")
|
|
|
|
|
|
|
|
vimdir_exists = os.path.isdir("/home/clay/Gitlab/linux-tools/testdirectory/")
|
2019-12-19 14:03:31 +01:00
|
|
|
autoloaddir_exists = os.path.isdir("/home/clay/Gitlab/linux-tools/testdirectory/autoload/")
|
2019-12-17 23:36:42 +01:00
|
|
|
|
2019-12-19 14:03:31 +01:00
|
|
|
# Create necessary folder structure for Plugin Manager
|
|
|
|
if autoloaddir_exists == False:
|
|
|
|
if vimdir_exists:
|
|
|
|
install_vimplug = "cd ~/Gitlab/linux-tools/testdirectory/ && mkdir autoload && cd autoload && touch test.txt"
|
|
|
|
call(install_vimplug, shell=True)
|
2019-12-17 23:36:42 +01:00
|
|
|
|
2019-12-19 14:03:31 +01:00
|
|
|
else:
|
|
|
|
make_vimdir = """cd ~/Gitlab/linux-tools/ && mkdir testdirectory && cd testdirectory && mkdir autoload &&
|
|
|
|
cd autoload && touch test.txt"""
|
2019-12-22 02:45:19 +01:00
|
|
|
call(make_vimdir, shell=True)
|
2019-12-17 23:36:42 +01:00
|
|
|
else:
|
2019-12-22 02:45:19 +01:00
|
|
|
print("Vim-Plug already installed!")
|