Fix path creation, add devenv path for testing
This commit is contained in:
parent
9ef6efcbc3
commit
371cdcc906
@ -1,9 +1,15 @@
|
|||||||
from AbstractModule import AbstractModule
|
|
||||||
from subprocess import call
|
|
||||||
from PyInquirer import prompt
|
|
||||||
from pathlib import Path
|
|
||||||
import os
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from PyInquirer import prompt
|
||||||
|
|
||||||
|
from AbstractModule import AbstractModule
|
||||||
|
|
||||||
|
|
||||||
|
def get_vim_root():
|
||||||
|
# return Path().home().joinpath(".vim")
|
||||||
|
return Path(os.getcwd()).joinpath("devenv", ".vim")
|
||||||
|
|
||||||
|
|
||||||
class VimModule(AbstractModule):
|
class VimModule(AbstractModule):
|
||||||
@ -36,6 +42,10 @@ class VimModule(AbstractModule):
|
|||||||
|
|
||||||
def run(self):
|
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()
|
selected_plugins = self.do_plugin_selection()
|
||||||
default_settings = list(self.settings.values())
|
default_settings = list(self.settings.values())
|
||||||
# print out selected plugins
|
# print out selected plugins
|
||||||
@ -45,18 +55,18 @@ class VimModule(AbstractModule):
|
|||||||
[print(i) for i in default_settings]
|
[print(i) for i in default_settings]
|
||||||
|
|
||||||
# Create vimrc file
|
# Create vimrc file
|
||||||
|
vimrc_path = str(get_vim_root().joinpath(".vimrc"))
|
||||||
try:
|
try:
|
||||||
with open("vim_testfile", "r") as vim_file:
|
with open(vimrc_path, "r") as vimrc_file:
|
||||||
vimrc_content = vim_file.readlines()
|
vimrc_content = vimrc_file.readlines()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
vimrc_content = []
|
vimrc_content = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
index = vimrc_content.index("call plug#begin('~/.vim/plugged')\n") + 1
|
index = vimrc_content.index("call plug#begin('~/.vim/plugged')\n") + 1
|
||||||
# print("Index of plugman " + str(index))
|
|
||||||
for plugin in selected_plugins:
|
for plugin in selected_plugins:
|
||||||
vimrc_content.insert(index, self.plugins[plugin] + "\n")
|
vimrc_content.insert(index, self.plugins[plugin] + "\n")
|
||||||
|
|
||||||
default_settings.reverse()
|
default_settings.reverse()
|
||||||
for setting in default_settings:
|
for setting in default_settings:
|
||||||
vimrc_content.insert(index - 1, setting + "\n")
|
vimrc_content.insert(index - 1, setting + "\n")
|
||||||
@ -70,28 +80,9 @@ class VimModule(AbstractModule):
|
|||||||
seen_add = seen.add
|
seen_add = seen.add
|
||||||
vimrc_content = [x1 for x1 in vimrc_content if not (x1 in seen or seen_add(x1))]
|
vimrc_content = [x1 for x1 in vimrc_content if not (x1 in seen or seen_add(x1))]
|
||||||
|
|
||||||
with open("vim_testfile", "w") as vimrc_file:
|
with open(vimrc_path, "w") as vimrc_file:
|
||||||
for line in vimrc_content:
|
for line in vimrc_content:
|
||||||
vimrc_file.write(line)
|
vimrc_file.write(line)
|
||||||
|
|
||||||
# Create necessary folder structure for Plugin Manager
|
# TODO: check if existing plugin manager file
|
||||||
autoload = str(Path.home().joinpath("Gitlab", "linux-tools", "testdirectory", "autoload"))
|
# TODO: else download plugin manager
|
||||||
testdirectory = str(Path.home().joinpath("Gitlab", "linux-tools", "testdirectory"))
|
|
||||||
if not os.path.isdir(autoload):
|
|
||||||
if os.path.isdir(testdirectory):
|
|
||||||
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)
|
|
||||||
else:
|
|
||||||
print("Vim-Plug already installed!")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user