diff options
-rw-r--r-- | lib/spack/spack/package.py | 1 | ||||
-rw-r--r-- | lib/spack/spack/package_completions.py | 48 | ||||
-rw-r--r-- | var/spack/repos/builtin/packages/fd/package.py | 16 | ||||
-rw-r--r-- | var/spack/repos/builtin/packages/git/package.py | 12 | ||||
-rw-r--r-- | var/spack/repos/builtin/packages/rclone/package.py | 12 | ||||
-rw-r--r-- | var/spack/repos/builtin/packages/restic/package.py | 16 | ||||
-rw-r--r-- | var/spack/repos/builtin/packages/ripgrep/package.py | 16 |
7 files changed, 120 insertions, 1 deletions
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index c8de3c2158..bf8538032a 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -99,6 +99,7 @@ from spack.package_base import ( install_dependency_symlinks, on_package_attributes, ) +from spack.package_completions import * from spack.spec import InvalidSpecDetected, Spec from spack.util.executable import * from spack.util.filesystem import file_command, fix_darwin_install_name, mime_type diff --git a/lib/spack/spack/package_completions.py b/lib/spack/spack/package_completions.py new file mode 100644 index 0000000000..b985d77093 --- /dev/null +++ b/lib/spack/spack/package_completions.py @@ -0,0 +1,48 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +from pathlib import Path +from typing import Union + +"""Functions relating to shell autocompletion scripts for packages.""" + + +def bash_completion_path(root: Union[str, Path]) -> Path: + """ + Return standard path for bash completion scripts under root. + + Args: + root: The prefix root under which to generate the path. + + Returns: + Standard path for bash completion scripts under root. + """ + return Path(root) / "share" / "bash-completion" / "completions" + + +def zsh_completion_path(root: Union[str, Path]) -> Path: + """ + Return standard path for zsh completion scripts under root. + + Args: + root: The prefix root under which to generate the path. + + Returns: + Standard path for zsh completion scripts under root. + """ + return Path(root) / "share" / "zsh" / "site-functions" + + +def fish_completion_path(root: Union[str, Path]) -> Path: + """ + Return standard path for fish completion scripts under root. + + Args: + root: The prefix root under which to generate the path. + + Returns: + Standard path for fish completion scripts under root. + """ + return Path(root) / "share" / "fish" / "vendor_completions.d" diff --git a/var/spack/repos/builtin/packages/fd/package.py b/var/spack/repos/builtin/packages/fd/package.py index 3bfc475c33..3711d53192 100644 --- a/var/spack/repos/builtin/packages/fd/package.py +++ b/var/spack/repos/builtin/packages/fd/package.py @@ -24,3 +24,19 @@ class Fd(CargoPackage): version("7.4.0", sha256="33570ba65e7f8b438746cb92bb9bc4a6030b482a0d50db37c830c4e315877537") depends_on("rust@1.64:", type="build", when="@9:") + + @run_after("install") + def install_completions(self): + fd = Executable(self.prefix.bin.fd) + + mkdirp(bash_completion_path(self.prefix)) + with open(bash_completion_path(self.prefix) / "fd", "w") as file: + fd("--gen-completions", "bash", output=file) + + mkdirp(fish_completion_path(self.prefix)) + with open(fish_completion_path(self.prefix) / "fd.fish", "w") as file: + fd("--gen-completions", "fish", output=file) + + mkdirp(zsh_completion_path(self.prefix)) + with open(zsh_completion_path(self.prefix) / "_fd", "w") as file: + fd("--gen-completions", "zsh", output=file) diff --git a/var/spack/repos/builtin/packages/git/package.py b/var/spack/repos/builtin/packages/git/package.py index 02c6aa7cd3..7f281682ee 100644 --- a/var/spack/repos/builtin/packages/git/package.py +++ b/var/spack/repos/builtin/packages/git/package.py @@ -263,7 +263,17 @@ class Git(AutotoolsPackage): @run_after("install") def install_completions(self): - install_tree("contrib/completion", self.prefix.share) + mkdirp(bash_completion_path(self.prefix)) + install( + "contrib/completion/git-completion.bash", + join_path(bash_completion_path(self.prefix), "git"), + ) + + mkdirp(zsh_completion_path(self.prefix)) + install( + "contrib/completion/git-completion.zsh", + join_path(zsh_completion_path(self.prefix), "_git"), + ) @run_after("install") def install_manpages(self): diff --git a/var/spack/repos/builtin/packages/rclone/package.py b/var/spack/repos/builtin/packages/rclone/package.py index 005e2ebbfb..741dd7293f 100644 --- a/var/spack/repos/builtin/packages/rclone/package.py +++ b/var/spack/repos/builtin/packages/rclone/package.py @@ -57,3 +57,15 @@ class Rclone(Package): def install(self, spec, prefix): mkdirp(prefix.bin) install("rclone", prefix.bin) + + @run_after("install") + def install_completions(self): + rclone = Executable(self.prefix.bin.rclone) + + mkdirp(bash_completion_path(self.prefix)) + mkdirp(fish_completion_path(self.prefix)) + mkdirp(zsh_completion_path(self.prefix)) + + rclone("genautocomplete", "bash", str(bash_completion_path(self.prefix) / "rclone")) + rclone("genautocomplete", "fish", str(fish_completion_path(self.prefix) / "rclone.fish")) + rclone("genautocomplete", "zsh", str(zsh_completion_path(self.prefix) / "_rclone")) diff --git a/var/spack/repos/builtin/packages/restic/package.py b/var/spack/repos/builtin/packages/restic/package.py index 342d614a04..7e94b05e21 100644 --- a/var/spack/repos/builtin/packages/restic/package.py +++ b/var/spack/repos/builtin/packages/restic/package.py @@ -44,3 +44,19 @@ class Restic(Package): def install(self, spec, prefix): mkdirp(prefix.bin) install("restic", prefix.bin) + + @run_after("install") + def install_completions(self): + restic = Executable(self.prefix.bin.restic) + + mkdirp(bash_completion_path(self.prefix)) + mkdirp(fish_completion_path(self.prefix)) + mkdirp(zsh_completion_path(self.prefix)) + + restic("generate", "--bash-completion", "restic.bash") + restic("generate", "--fish-completion", "restic.fish") + restic("generate", "--zsh-completion", "_restic") + + install("restic.bash", bash_completion_path(self.prefix)) + install("restic.fish", fish_completion_path(self.prefix)) + install("_restic", zsh_completion_path(self.prefix)) diff --git a/var/spack/repos/builtin/packages/ripgrep/package.py b/var/spack/repos/builtin/packages/ripgrep/package.py index cfa392714c..ee30a1420d 100644 --- a/var/spack/repos/builtin/packages/ripgrep/package.py +++ b/var/spack/repos/builtin/packages/ripgrep/package.py @@ -26,3 +26,19 @@ class Ripgrep(CargoPackage): version("11.0.2", sha256="0983861279936ada8bc7a6d5d663d590ad34eb44a44c75c2d6ccd0ab33490055") depends_on("rust@1.72:", type="build", when="@14:") + + @run_after("install") + def install_completions(self): + rg = Executable(self.prefix.bin.rg) + + mkdirp(bash_completion_path(self.prefix)) + with open(bash_completion_path(self.prefix) / "rg", "w") as file: + rg("--generate", "complete-bash", output=file) + + mkdirp(fish_completion_path(self.prefix)) + with open(fish_completion_path(self.prefix) / "rg.fish", "w") as file: + rg("--generate", "complete-fish", output=file) + + mkdirp(zsh_completion_path(self.prefix)) + with open(zsh_completion_path(self.prefix) / "_rg", "w") as file: + rg("--generate", "complete-zsh", output=file) |