Fix install of completion if dirs missing

Fixes situations if completion directories are missing and adds tests for installer.
This commit is contained in:
OMEGARAZER
2022-12-19 17:54:34 -05:00
parent 2e2dfe671b
commit 5d3a539eda
2 changed files with 59 additions and 0 deletions

View File

@@ -17,6 +17,9 @@ class Completion:
def install(self):
if self.shell in ("all", "bash"):
comp_dir = self.share_dir + "/bash-completion/completions/"
if not os.path.exists(comp_dir):
print("Creating Bash completion directory.")
os.makedirs(comp_dir, exist_ok=True)
for point in self.entry_points:
self.env[f"_{point.upper().replace('-', '_')}_COMPLETE"] = "bash_source"
with open(comp_dir + point, "w") as file:
@@ -24,6 +27,9 @@ class Completion:
print(f"Bash completion for {point} written to {comp_dir}{point}")
if self.shell in ("all", "fish"):
comp_dir = self.share_dir + "/fish/vendor_completions.d/"
if not os.path.exists(comp_dir):
print("Creating Fish completion directory.")
os.makedirs(comp_dir, exist_ok=True)
for point in self.entry_points:
self.env[f"_{point.upper().replace('-', '_')}_COMPLETE"] = "fish_source"
with open(comp_dir + point + ".fish", "w") as file:
@@ -31,6 +37,9 @@ class Completion:
print(f"Fish completion for {point} written to {comp_dir}{point}.fish")
if self.shell in ("all", "zsh"):
comp_dir = self.share_dir + "/zsh/site-functions/"
if not os.path.exists(comp_dir):
print("Creating Zsh completion directory.")
os.makedirs(comp_dir, exist_ok=True)
for point in self.entry_points:
self.env[f"_{point.upper().replace('-', '_')}_COMPLETE"] = "zsh_source"
with open(comp_dir + "_" + point, "w") as file: