Add zsh completions

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2025-01-10 16:35:58 +00:00
parent 465198f3c8
commit d967d5d603
9 changed files with 101 additions and 126 deletions

34
flake.lock generated
View File

@@ -119,24 +119,6 @@
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"home-manager": {
"inputs": {
"nixpkgs": [
@@ -215,7 +197,6 @@
"ags": "ags",
"astal": "astal_2",
"disko": "disko",
"flake-utils": "flake-utils",
"home-manager": "home-manager",
"nixpkgs": "nixpkgs",
"nur": "nur",
@@ -264,21 +245,6 @@
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [

View File

@@ -45,10 +45,6 @@
url = "github:nix-community/NUR";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
astal = {
url = "github:aylur/astal";
inputs.nixpkgs.follows = "nixpkgs";
@@ -67,49 +63,39 @@
outputs =
{ self, nixpkgs, ... }@inputs:
let
pkgs = nixpkgs.legacyPackages."x86_64-linux";
in
{
nixosConfigurations = {
installer = nixpkgs.lib.nixosSystem {
specialArgs = {
inherit inputs;
};
specialArgs = { inherit inputs; };
system = "x86_64-linux";
modules = [ ./hosts/installer ];
};
eirene = nixpkgs.lib.nixosSystem {
specialArgs = {
inherit inputs;
};
specialArgs = { inherit inputs; };
system = "x86_64-linux";
modules = [ ./hosts/eirene ];
};
elara = nixpkgs.lib.nixosSystem {
specialArgs = {
inherit inputs;
};
specialArgs = { inherit inputs; };
system = "x86_64-linux";
modules = [ ./hosts/elara ];
};
};
}
// inputs.flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells = {
bun = import ./hosts/common/shells/bun { inherit pkgs; };
go = import ./hosts/common/shells/go { inherit pkgs; };
java = import ./hosts/common/shells/java { inherit pkgs; };
nix = import ./hosts/common/shells/nix { inherit pkgs; };
nodejs = import ./hosts/common/shells/nodejs { inherit pkgs; };
python = import ./hosts/common/shells/python { inherit pkgs; };
};
formatter = pkgs.nixfmt-rfc-style;
}
);
devShells = {
bun = import ./hosts/common/shells/bun { inherit pkgs; };
go = import ./hosts/common/shells/go { inherit pkgs; };
java = import ./hosts/common/shells/java { inherit pkgs; };
nix = import ./hosts/common/shells/nix { inherit pkgs; };
nodejs = import ./hosts/common/shells/nodejs { inherit pkgs; };
python = import ./hosts/common/shells/python { inherit pkgs; };
};
formatter = pkgs.nixfmt-rfc-style;
};
}

View File

@@ -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" ];
};
};
}

View File

@@ -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
'';
};
}

View File

@@ -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" ];

View File

@@ -23,7 +23,7 @@ in
wayland.windowManager.hyprland.settings.bind = [
"Ctrl_Alt, r, exec, ${themeBin}"
"Ctrl_Alt, t, exec, ${themeBin} toggle"
"Ctrl_Alt, t, exec, ${themeBin} -m toggle"
];
};
}

View File

@@ -532,5 +532,7 @@ in
}) cfg.template;
}
);
programs.zsh.initExtra = builtins.readFile ./theme.completion.sh;
};
}

View File

@@ -0,0 +1,11 @@
_theme-completion() {
local options=(
'-m[set mode: light, dark, or toggle]:mode:(light dark toggle)'
'-w[set wallpaper: specify file path]:file:_files'
)
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments -s $options
}
compdef _theme-completion theme

View File

@@ -10,15 +10,6 @@ set_wallpaper() {
fi
}
set_mode() {
if [[ "$1" = "light" ]] || [[ "$1" = "dark" ]]; then
MODE="$1"
else
echo "Invalid mode: $1. Use 'light' or 'dark'."
exit 1
fi
}
toggle_mode() {
if [[ "$(cat "${CONFIG}"/mode)" = "light" ]]; then
MODE="dark"
@@ -28,7 +19,7 @@ toggle_mode() {
}
show_usage() {
echo "Usage: theme {toggle|light|dark|mode <mode>|wallpaper <file> [mode]}"
echo "Usage: theme [-m {light|dark|toggle}] [-w <file>]"
}
finish() {
@@ -39,56 +30,31 @@ finish() {
"${RELOAD}" > /dev/null
}
if [[ $# -eq 0 ]]; then
finish
else
case "$1" in
toggle)
if [[ $# -eq 1 ]]; then
toggle_mode
else
show_usage
exit 1
fi
# Parse arguments
while getopts "m:w:" opt; do
case "$opt" in
m)
case "$OPTARG" in
light|dark)
MODE="$OPTARG"
;;
toggle)
toggle_mode
;;
*)
show_usage
exit 1
;;
esac
;;
light)
if [[ $# -eq 1 ]]; then
set_mode "light"
else
show_usage
exit 1
fi
;;
dark)
if [[ $# -eq 1 ]]; then
set_mode "dark"
else
show_usage
exit 1
fi
;;
mode)
if [[ $# -eq 2 ]]; then
set_mode "$2"
else
show_usage
exit 1
fi
;;
wallpaper)
if [[ $# -ge 2 ]] && [[ $# -le 3 ]]; then
set_wallpaper "$2"
[[ $# -eq 3 ]] && set_mode "$3"
else
show_usage
exit 1
fi
w)
set_wallpaper "$OPTARG"
;;
*)
show_usage
exit 1
;;
esac
done
finish
fi
finish