55import argparse
66from pathlib import Path
77from datetime import datetime
8+
9+ # import pynvim and install it if it's not already installed
10+ try :
11+ from pynvim import attach
12+ except ImportError :
13+ # install pip if it's not installed
14+ try :
15+ import pip
16+ except :
17+ command = ["python3" , "-m" , "ensurepip" , "--default-pip" ]
18+ subprocess .run (command )
19+ command = ['pip' , 'install' , 'pynvim' ]
20+ subprocess .run (command )
21+ from pynvim import attach
822# -------------------------------
923
1024
4458
4559# directory locations
4660# -------------------------------
61+ nvim = attach ('child' , argv = ["/bin/env" , "nvim" , "--embed" , "--headless" ])
62+
4763HOME = Path .home ()
48- CACHE = f"{ HOME } /.cache"
49- CONFIG = f"{ HOME } /.config"
50- CACHE_BUILD_PATH = f"{ CACHE } /build_files"
51- NVIM_CONF_PATH = f"{ CONFIG } /nvim"
52- NVIM_PLUG_PATH = f"{ HOME } /.local/share/nvim"
53- CUSTOM_TOOLS_DIR = f"{ NVIM_PLUG_PATH } /custom_tools"
64+ NVIM_DATA_DIR = nvim .funcs .stdpath ('data' )
65+ NVIM_CONF_PATH = nvim .funcs .stdpath ('config' )
66+
67+ CONFIG = NVIM_CONF_PATH .split ("nvim" )[0 ]
68+ CACHE = f"{ NVIM_DATA_DIR } /.cache"
69+ CUSTOM_TOOLS_DIR = f"{ NVIM_DATA_DIR } /custom_tools"
70+ CACHE_BUILD_PATH = f"{ HOME } /.cache/build_files"
5471SCRIPT_PATH = Path (__file__ ).parent .absolute ()
5572# -------------------------------
5673
5774# directories we must have
5875# -------------------------------
5976require_dir = [
6077 f"{ CONFIG } " ,
61- f"{ CACHE } /nvim/swap" ,
62- f"{ CACHE } /nvim/view" ,
63- f"{ CACHE } /nvim/shada" ,
64- f"{ CACHE } /nvim/backedUP" ,
65- f"{ CACHE } /nvim/undos" ,
66- f"{ CACHE } /build_files" ,
78+ f"{ CACHE } /swap" ,
79+ f"{ CACHE } /view" ,
80+ f"{ CACHE } /shada" ,
81+ f"{ CACHE } /backedUP" ,
82+ f"{ CACHE } /undos" ,
6783 CUSTOM_TOOLS_DIR ,
6884 CACHE_BUILD_PATH ,
6985]
@@ -81,7 +97,7 @@ def create_require_dir(dirs):
8197 print ("creating required directories..." )
8298 once = False
8399 Path (dir ).mkdir (parents = True )
84- print (" " ,dir )
100+ print (" " , dir )
85101# -------------------------------
86102
87103
@@ -111,8 +127,8 @@ def abstract_git():
111127 """check if abstract exist as a git project"""
112128 if Path (NVIM_CONF_PATH ).exists ():
113129 if Path (f"{ NVIM_CONF_PATH } /.__abstract__" ).is_file ():
114- if Path (f"{ NVIM_CONF_PATH } /.git" ).exists ():
115- return True
130+ if Path (f"{ NVIM_CONF_PATH } /.git" ).exists ():
131+ return True
116132 return False
117133# -------------------------------
118134
@@ -135,22 +151,21 @@ def need_to_clone_abstract():
135151
136152# -------------------------------
137153def compile_nvim ():
138- print ( "\n press CTRL+C if it's taking while \n " )
139- packer_compile_cmd = [ "nvim" , "--headless" , "-c" , "autocmd User PackerComplete quitall" , "-c" , "PackerSync" ]
154+ print ("\n press CTRL+C if it's taking while \n " )
155+ packer_compile_cmd = ["nvim" , "--headless" , "-c" , "autocmd User PackerComplete quitall" , "-c" , "PackerSync" ]
140156 subprocess .run (packer_compile_cmd )
141157
142158# -------------------------------
143159
144160
145161# -------------------------------
146162def setup_packer ():
147- nvim_plugin_dir = str (f"{ HOME } /.local/share/nvim /site/pack/packer/start" )
163+ nvim_plugin_dir = str (f"{ NVIM_DATA_DIR } /site/pack/packer/start" )
148164 packer_dir = nvim_plugin_dir + "/packer.nvim"
149165 if not Path (packer_dir ).exists ():
150166 print ("\n setting up packer..." )
151167 if not Path (nvim_plugin_dir ).exists ():
152168 Path (nvim_plugin_dir ).mkdir (parents = True )
153-
154169 repository = "https://github.com/wbthomason/packer.nvim"
155170 subprocess .run (["git" , "clone" , "--depth" , "1" , repository ], cwd = nvim_plugin_dir )
156171# -------------------------------
0 commit comments