Better shell completion support for packages (#44756)
This commit is contained in:
parent
07e964c688
commit
5c8d22c597
@ -99,6 +99,7 @@
|
||||
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
|
||||
|
48
lib/spack/spack/package_completions.py
Normal file
48
lib/spack/spack/package_completions.py
Normal file
@ -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"
|
@ -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)
|
||||
|
@ -263,7 +263,17 @@ def install(self, spec, prefix):
|
||||
|
||||
@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):
|
||||
|
@ -57,3 +57,15 @@ def build(self, spec, prefix):
|
||||
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"))
|
||||
|
@ -44,3 +44,19 @@ def build(self, spec, prefix):
|
||||
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))
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user