diff --git a/modules/system.nix b/modules/system.nix index 13804ce..c82ee47 100644 --- a/modules/system.nix +++ b/modules/system.nix @@ -5,6 +5,7 @@ ./overlay-pkgs ./user ./emacs + ./zsh ]; programs.dconf.enable = true; diff --git a/modules/zsh/completion.zsh b/modules/zsh/completion.zsh new file mode 100755 index 0000000..6d3b257 --- /dev/null +++ b/modules/zsh/completion.zsh @@ -0,0 +1,27 @@ +# completion types +zstyle ':completion:*' completer _extensions _complete + +# jump directly to first completion +zstyle ':completion:::::default' menu yes select + +# matching +zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[.+-]=* r:|=*' 'l:|=* r:|=*' + +# allow highlight/menu move in completions +zstyle ':completion:*' menu select + +# styles +zstyle ':completion:*:*:*:*:descriptions' format '%F{green}// %d%f' +zstyle ':completion:*:*:*:*:corrections' format '%F{yellow}// %d%f' +zstyle ':completion:*:messages' format '%F{purple}// %d%f' +zstyle ':completion:*:warnings' format '%F{red}// no completions availible%f' + +# group results under headers +zstyle ':completion:*' group-name '' +zstyle ':completion:*:*:-command-:*:*' group-order alias builtins functions commands + +# file colors +zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} + +# use --help completions when availible +compdef _gnu_generic -default- -P '*' diff --git a/modules/zsh/default.nix b/modules/zsh/default.nix new file mode 100644 index 0000000..302c439 --- /dev/null +++ b/modules/zsh/default.nix @@ -0,0 +1,67 @@ +{ pkgs, config, impurity, ... }: { + # put it in /etc/shells + programs.zsh.enable = true; + + users.users.${config.main-user}.shell = pkgs.zsh; + + home-manager.users.${config.main-user} = { config, ... }: let + zshDir = ".config/zsh"; + zshPath = "${config.home.homeDirectory}/${zshDir}"; + + history = 1000000; + in { + programs.zsh = { + enable = true; + + # path to zsh configs + dotDir = zshDir; + enableCompletion = true; + + history = { + path = "${zshPath}/history"; + + # lines of history to save + save = history; + size = history; + }; + + plugins = [ + { + name = "zsh-syntax-highlighting"; + src = pkgs.fetchFromGitHub { + owner = "zsh-users"; + repo = "zsh-syntax-highlighting"; + rev = "master"; + sha256 = "iKx7lsQCoSAbpANYFkNVCZlTFdwOEI34rx/h1rnraSg="; + }; + } + { + name = "zsh-completions"; + src = pkgs.fetchFromGitHub { + owner = "zsh-users"; + repo = "zsh-completions"; + rev = "master"; + sha256 = "MRGIKZtXk1+Yb8AV4NOqpSiP4IkWxPTJoLftq7VDjoE="; + }; + } + { + name = "zsh-autosuggestions"; + src = pkgs.fetchFromGitHub { + owner = "zsh-users"; + repo = "zsh-autosuggestions"; + rev = "master"; + sha256 = "KLUYpUu4DHRumQZ3w59m9aTW6TBKMCXl2UcKi4uMd7w="; + }; + } + ]; + + initExtra = '' + # keybinds + source ${impurity.link ./keybinds.zsh} + + # completions + source ${impurity.link ./completion.zsh} + ''; + }; + }; +} diff --git a/modules/zsh/keybinds.zsh b/modules/zsh/keybinds.zsh new file mode 100755 index 0000000..622871f --- /dev/null +++ b/modules/zsh/keybinds.zsh @@ -0,0 +1,14 @@ +autoload -U up-line-or-beginning-search +autoload -U down-line-or-beginning-search +zle -N up-line-or-beginning-search +zle -N down-line-or-beginning-search +bindkey "^[[A" up-line-or-beginning-search +bindkey "^[[B" down-line-or-beginning-search +bindkey "^[OA" up-line-or-beginning-search +bindkey "^[OB" down-line-or-beginning-search +bindkey "^K" up-line-or-beginning-search +bindkey "^J" down-line-or-beginning-search +bindkey "^[[1;5D" backward-word +bindkey "^[[1;5C" forward-word +bindkey "^H" backward-char +bindkey "^L" forward-char