Add zsh completions
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -11,6 +11,32 @@
|
||||
kind
|
||||
];
|
||||
|
||||
programs.zsh.p10k.extraRightPromptElements = [ "kubecontext" ];
|
||||
programs.zsh = {
|
||||
initExtra = ''
|
||||
kubeswitch() {
|
||||
local target="$HOME/.kube/$1"
|
||||
local config="$HOME/.kube/config"
|
||||
|
||||
if [[ -f "$target" && "$target" != "$config" ]]; then
|
||||
ln -sf "$target" "$config"
|
||||
echo "Switched kube context to $1"
|
||||
p10k reload
|
||||
else
|
||||
echo "Invalid kube context: $1"
|
||||
echo "Ensure the file exists in ~/.kube"
|
||||
fi
|
||||
}
|
||||
|
||||
_kubeswitch-completion() {
|
||||
local dir="$HOME/.kube"
|
||||
local config="$dir/config"
|
||||
compadd -- ''${(f)"$(find "$dir" -maxdepth 1 \( -type f -o -type l \) -not -name 'config' -exec basename {} \;)"}
|
||||
}
|
||||
|
||||
compdef _kubeswitch-completion kubeswitch
|
||||
'';
|
||||
|
||||
p10k.extraRightPromptElements = [ "kubecontext" ];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@@ -2,12 +2,14 @@
|
||||
user ? throw "user argument is required",
|
||||
home ? throw "home argument is required",
|
||||
}:
|
||||
{ ... }:
|
||||
{ lib, inputs, ... }:
|
||||
{
|
||||
home-manager.users.${user}.programs.zsh = {
|
||||
shellAliases.nd = "nix-develop";
|
||||
|
||||
initExtra = ''
|
||||
initExtra = let
|
||||
devShells = lib.strings.concatStringsSep " " (lib.attrsets.mapAttrsToList (key: _: key) inputs.self.devShells);
|
||||
in ''
|
||||
nix-develop() {
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: nix-develop <shell>"
|
||||
@@ -15,6 +17,13 @@
|
||||
fi
|
||||
nix develop self#"$1" -c "$SHELL"
|
||||
}
|
||||
|
||||
_nix-develop-completion() {
|
||||
local shells=(${devShells})
|
||||
compadd -- $shells
|
||||
}
|
||||
|
||||
compdef _nix-develop-completion nix-develop
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
user ? throw "user argument is required",
|
||||
home ? throw "home argument is required",
|
||||
}:
|
||||
{ inputs, ... }:
|
||||
{ lib, inputs, ... }:
|
||||
{
|
||||
home-manager.users.${user} = {
|
||||
programs = {
|
||||
@@ -16,7 +16,9 @@
|
||||
zsh = {
|
||||
shellAliases.nde = "nix-direnv";
|
||||
|
||||
initExtra = ''
|
||||
initExtra = let
|
||||
devShells = lib.strings.concatStringsSep " " (lib.attrsets.mapAttrsToList (key: _: key) inputs.self.devShells);
|
||||
in ''
|
||||
nix-direnv() {
|
||||
if [ -z "$1" ]; then
|
||||
echo "use flake" > .envrc
|
||||
@@ -34,6 +36,13 @@
|
||||
|
||||
direnv allow
|
||||
}
|
||||
|
||||
_nix-direnv-completion() {
|
||||
local shells=(${devShells})
|
||||
compadd -- $shells
|
||||
}
|
||||
|
||||
compdef _nix-direnv-completion nix-direnv
|
||||
'';
|
||||
|
||||
p10k.extraRightPromptElements = [ "direnv" ];
|
||||
|
Reference in New Issue
Block a user