Zsh: Difference between revisions

Layer-09 (talk | contribs)
I divided the information into more manageable sections and formatted the code using Alejandra. Additionally, I added references and some other options.
Likivik (talk | contribs)
 
(3 intermediate revisions by 3 users not shown)
Line 10: Line 10:
== Configuration ==
== Configuration ==


==== 3.1 Basic ====
==== Basic ====
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
programs.zsh = {
programs.zsh = {
Line 17: Line 17:
</syntaxhighlight>
</syntaxhighlight>


==== 3.2 Advanced ====
==== Advanced ====
The configuration below is using home manager, but a more limited version of it can be achieved if system-wide.<syntaxhighlight lang="nix">
The configuration below is using home manager, but a more limited version of it can be achieved if system-wide.<syntaxhighlight lang="nix">
programs.zsh = {
programs.zsh = {
Line 40: Line 40:
== Tips and Tricks ==
== Tips and Tricks ==


==== 4.1 Where to see a list of options? ====
==== Where to see a list of options? ====
The home manager options are defined in the following [https://nix-community.github.io/home-manager/options.xhtml#opt-programs.zsh.enable Home Manager Options Manual].
The home manager options are defined in the following [https://nix-community.github.io/home-manager/options.xhtml#opt-programs.zsh.enable Home Manager Options Manual] or can be looked up at [https://home-manager-options.extranix.com/?query=zsh&release=master Home Manager Option Search].


The system-wide options are listed on [https://mynixos.com/search?q=zsh MyNixOS].
The system-wide options are listed on [https://mynixos.com/search?q=zsh MyNixOS].


==== 4.2 How to use plugins? ====
==== How to use plugins? ====
Home manager has three ways of managing plugins: '''Zplug''', '''Oh-My-Zsh''' and '''Manual'''.<syntaxhighlight lang="nix">
Home manager has four ways of managing plugins: '''[http://zplug.github.io/ Zplug]''', '''[https://ohmyz.sh/ Oh-My-Zsh], [https://getantidote.github.io/ Antidote]''' and '''Manual'''.<syntaxhighlight lang="nix">
programs.zsh = {
programs.zsh = {
   enable = true;
   enable = true;


# With Zplug:
   zplug = {
   zplug = {
     enable = true;
     enable = true;
Line 56: Line 57:
       {
       {
         name = "romkatv/powerlevel10k";
         name = "romkatv/powerlevel10k";
         tags = [as:theme depth:1];
         tags = [ "as:theme" "depth:1" ];
       } # Installations with additional options. For the list of options, please refer to Zplug README.
       } # Installations with additional options. For the list of options, please refer to Zplug README.
     ];
     ];
   };
   };


# With Oh-My-Zsh:
   ohMyZsh = {
   ohMyZsh = {
     enable = true;
     enable = true;
Line 67: Line 69:
   };
   };


# With Antidote:
  antidote = {
    enable = true;
    plugins = [''
      zsh-users/zsh-autosuggestions
      ohmyzsh/ohmyzsh path:lib/git.zsh
    '']; # explanation of "path:..." and other options explained in Antidote README.
# Manual
   plugins = [
   plugins = [
     {
     {
Line 102: Line 113:
== Troubleshooting ==
== Troubleshooting ==


==== 5.1 Zsh-autocomplete not working ====
==== Zsh-autocomplete not working ====
You may have some issues with the {{ic|marlonrichert/zsh-autocomplete}} plugin on NixOS. That's because the default NixOS configuration overrides keybinds for up and down arrow keys. To fix this issue, you need to add this somewhere in your .zshrc (either manually if your .zshrc is not managed by Nix, or with {{ic|packages.zsh.initExtra}})
You may have some issues with the {{ic|marlonrichert/zsh-autocomplete}} plugin on NixOS. That's because the default NixOS configuration overrides keybinds for up and down arrow keys. To fix this issue, you need to add this somewhere in your .zshrc (either manually if your .zshrc is not managed by Nix, or with {{ic|packages.zsh.initExtra}})
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 108: Line 119:
</syntaxhighlight>
</syntaxhighlight>


==== 5.2 SHA Mismatch during manual plugin installation ====
==== SHA Mismatch during manual plugin installation ====
If manual plugin installation fails with SHA mismatch, generating a valid hash as part of the error message can be achieved by temporarily switching to:
If manual plugin installation fails with SHA mismatch, generating a valid hash as part of the error message can be achieved by temporarily switching to:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 117: Line 128:
Redoing this is mandatory if one wants to update to a newer commit of the targeted plugin repository.  
Redoing this is mandatory if one wants to update to a newer commit of the targeted plugin repository.  


==== 5.3 GDM does not show user when zsh is the default shell ====
==== GDM does not show user when zsh is the default shell ====
GDM only shows users that have their default shell set to a shell listed in /etc/shells. Setting the default shell using the following does not update /etc/shells.
GDM only shows users that have their default shell set to a shell listed in /etc/shells. Setting the default shell using the following does not update /etc/shells.
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 125: Line 136:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
environment.shells = with pkgs; [ zsh ];
environment.shells = with pkgs; [ zsh ];
</syntaxhighlight>
==== Hide configuration for new users ====
Meaning this message:<syntaxhighlight lang="zsh">
This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.
You can:
(q)  Quit and do nothing.  The function will be run again next time.
(0)  Exit, creating the file ~/.zshrc containing just a comment.
    That will prevent this function being run again.
(1)  Continue to the main menu.
--- Type one of the keys in parentheses ---
</syntaxhighlight>You can hide this message by adding following line to the system configuration:<syntaxhighlight lang="nixos">
# Prevent the new user dialog in zsh
system.userActivationScripts.zshrc = "touch .zshrc";
</syntaxhighlight>
</syntaxhighlight>