diff --git a/flake.lock b/flake.lock index e1a2fd5..15ab3d2 100644 --- a/flake.lock +++ b/flake.lock @@ -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": [ diff --git a/flake.nix b/flake.nix index e255b99..29c8f3d 100644 --- a/flake.nix +++ b/flake.nix @@ -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; + }; } diff --git a/hosts/common/configs/user/console/kubernetes/default.nix b/hosts/common/configs/user/console/kubernetes/default.nix index 0f7d2a4..636d68c 100644 --- a/hosts/common/configs/user/console/kubernetes/default.nix +++ b/hosts/common/configs/user/console/kubernetes/default.nix @@ -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" ]; + }; }; } diff --git a/hosts/common/configs/user/console/nix-develop/default.nix b/hosts/common/configs/user/console/nix-develop/default.nix index d790ec8..f6bb465 100644 --- a/hosts/common/configs/user/console/nix-develop/default.nix +++ b/hosts/common/configs/user/console/nix-develop/default.nix @@ -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 " @@ -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 ''; }; } diff --git a/hosts/common/configs/user/console/nix-direnv/default.nix b/hosts/common/configs/user/console/nix-direnv/default.nix index da24002..8202947 100644 --- a/hosts/common/configs/user/console/nix-direnv/default.nix +++ b/hosts/common/configs/user/console/nix-direnv/default.nix @@ -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" ]; diff --git a/hosts/common/configs/user/gui/theme/default.nix b/hosts/common/configs/user/gui/theme/default.nix index 7234a76..a1bcf61 100644 --- a/hosts/common/configs/user/gui/theme/default.nix +++ b/hosts/common/configs/user/gui/theme/default.nix @@ -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" ]; }; } diff --git a/hosts/common/configs/user/gui/theme/options.nix b/hosts/common/configs/user/gui/theme/options.nix index 66c3425..1cc2443 100644 --- a/hosts/common/configs/user/gui/theme/options.nix +++ b/hosts/common/configs/user/gui/theme/options.nix @@ -532,5 +532,7 @@ in }) cfg.template; } ); + + programs.zsh.initExtra = builtins.readFile ./theme.completion.sh; }; } diff --git a/hosts/common/configs/user/gui/theme/theme.completion.sh b/hosts/common/configs/user/gui/theme/theme.completion.sh new file mode 100644 index 0000000..d5faec1 --- /dev/null +++ b/hosts/common/configs/user/gui/theme/theme.completion.sh @@ -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 diff --git a/hosts/common/configs/user/gui/theme/theme.sh b/hosts/common/configs/user/gui/theme/theme.sh index c407a8e..d48ba6b 100644 --- a/hosts/common/configs/user/gui/theme/theme.sh +++ b/hosts/common/configs/user/gui/theme/theme.sh @@ -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 |wallpaper [mode]}" + echo "Usage: theme [-m {light|dark|toggle}] [-w ]" } 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