From 532107493512bb56581df1c60166830e44bd5076 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Thu, 12 Mar 2026 19:48:47 +0530 Subject: Added wrapper functions for devenv shell, nix-shell and nix develop commands that starts the environment in zsh automatically --- modules/tools/zsh/default.nix | 11 +++++++++-- modules/tools/zsh/nix-aliases.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 modules/tools/zsh/nix-aliases.sh (limited to 'modules/tools/zsh') diff --git a/modules/tools/zsh/default.nix b/modules/tools/zsh/default.nix index 0fed380..fcb7829 100644 --- a/modules/tools/zsh/default.nix +++ b/modules/tools/zsh/default.nix @@ -4,12 +4,15 @@ options.tools.zsh = { enable = lib.mkEnableOption "Enables zsh."; }; - - config = lib.mkIf config.tools.zsh.enable { + + config = let + nixCommandWrappers = builtins.readFile ./nix-aliases.sh; + in lib.mkIf config.tools.zsh.enable { programs.zsh = { enable = true; dotDir = "${config.xdg.configHome}/zsh"; history.path = "${config.xdg.cacheHome}/zsh/history"; + enableCompletion = true; initContent = '' setopt PROMPT_SUBST @@ -17,9 +20,13 @@ bindkey "^[[3~" delete-char bindkey "^?" backward-delete-char + ${nixCommandWrappers} ''; }; + programs.bash.initExtra = lib.mkIf config.programs.bash.enable + (lib.mkAfter nixCommandWrappers); + home.sessionVariables.SHELL = "${config.programs.zsh.package}/bin/zsh"; }; } diff --git a/modules/tools/zsh/nix-aliases.sh b/modules/tools/zsh/nix-aliases.sh new file mode 100644 index 0000000..0a2f453 --- /dev/null +++ b/modules/tools/zsh/nix-aliases.sh @@ -0,0 +1,27 @@ +nix-shell() { + for arg in "$@"; do + if [[ "$arg" == "--run" || "$arg" == "--command" ]]; then + command nix-shell "$@" + return + fi + done + + command nix-shell "$@" --run "$SHELL" +} + +nix() { + if [[ "$1" == "develop" ]]; then + local args=("${@:2}") + + for arg in "${args[@]}"; do + if [[ "$arg" == "-c" || "$arg" == "--command" ]]; then + command nix "$@" + return + fi + done + + command nix develop "${args[@]}" -c "$SHELL" + else + command nix "$@" + fi +} -- cgit v1.2.3