From f7c94a461c954e9ddf7965eec32dc5615503b6eb Mon Sep 17 00:00:00 2001 From: Evie Litherland-Smith Date: Tue, 7 Jan 2025 15:15:47 +0000 Subject: [PATCH] Switch to Zsh as default shell --- system/default.nix | 2 ++ system/home/shell/default.nix | 31 +++++++++++++++++++++++++++++++ system/home/shell/transient.zsh | 31 +++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 system/home/shell/transient.zsh diff --git a/system/default.nix b/system/default.nix index f3481475..831fb023 100644 --- a/system/default.nix +++ b/system/default.nix @@ -110,6 +110,7 @@ isNormalUser = true; group = "users"; description = "Evie Litherland-Smith"; + shell = pkgs.zsh; extraGroups = [ "networkmanager" "wheel" @@ -171,6 +172,7 @@ localBinInPath = true; }; programs = { + zsh.enable = true; command-not-found.enable = false; ssh.startAgent = true; nano = { diff --git a/system/home/shell/default.nix b/system/home/shell/default.nix index 282a9a02..e5cd6839 100644 --- a/system/home/shell/default.nix +++ b/system/home/shell/default.nix @@ -21,6 +21,37 @@ # Shells bash.enable = true; nushell.enable = true; + zsh = { + enable = true; + enableCompletion = true; + autocd = true; + autosuggestion.enable = true; + defaultKeymap = "emacs"; + syntaxHighlighting = { + enable = true; + highlighters = [ + "brackets" + "cursor" + ]; + }; + historySubstringSearch.enable = true; + history = { + extended = true; + share = true; + ignoreDups = true; + ignoreAllDups = true; + ignoreSpace = true; + expireDuplicatesFirst = true; + }; + initExtra = '' + ## completion config and styling + zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' + zstyle ':completion:*' menu 'select=long-list' + + ## transient prompt + source ${./transient.zsh} + ''; + }; # CLI programs and utilities btop.enable = true; carapace.enable = true; diff --git a/system/home/shell/transient.zsh b/system/home/shell/transient.zsh new file mode 100644 index 00000000..1f7bbd82 --- /dev/null +++ b/system/home/shell/transient.zsh @@ -0,0 +1,31 @@ +#!/usr/bin/env zsh + +zle-line-init() { + emulate -L zsh + + [[ $CONTEXT == start ]] || return 0 + + while true; do + zle .recursive-edit + local -i ret=$? + [[ $ret == 0 && $KEYS == $'\4' ]] || break + [[ -o ignore_eof ]] || exit 0 + done + + local saved_prompt=$PROMPT + local saved_rprompt=$RPROMPT + PROMPT='󰁔 ' + RPROMPT='' + zle .reset-prompt + PROMPT=$saved_prompt + RPROMPT=$saved_rprompt + + if ((ret)); then + zle .send-break + else + zle .accept-line + fi + return ret +} + +zle -N zle-line-init