Jump to content

Zsh: Difference between revisions

1,861 bytes added ,  15 May
imported>Flexagoon
No edit summary
(30 intermediate revisions by 24 users not shown)
Line 1: Line 1:
[https://www.zsh.org/ Zsh] is a powerful [[shell]] that operates as both an interactive shell and as a scripting language interpreter. While being compatible with the POSIX sh (not by default, only if issuing {{ic|emulate sh}}), it offers advantages such as improved [http://zsh.sourceforge.net/Guide/zshguide06.html tab completion] and [http://zsh.sourceforge.net/Doc/Release/Expansion.html globbing].
[https://www.zsh.org/ Zsh] is a powerful [[Command Shell|shell]] that operates as both an interactive shell and as a scripting language interpreter. While being compatible with the POSIX sh (not by default, only if issuing {{ic|emulate sh}}), it offers advantages such as improved [http://zsh.sourceforge.net/Guide/zshguide06.html tab completion] and [http://zsh.sourceforge.net/Doc/Release/Expansion.html globbing].


The [http://zsh.sourceforge.net/FAQ/zshfaq01.html#l4 Zsh FAQ] offers more reasons to use Zsh.
The [http://zsh.sourceforge.net/FAQ/zshfaq01.html#l4 Zsh FAQ] offers more reasons to use Zsh.


== Installation ==
== Installation ==
See [[Command Shell#Changing default shell]].
See [[Command Shell]].


== Configuration ==
== Configuration ==
Zsh can be configured with [[Home Manager]].
Zsh can be configured with [[Home Manager]].


Full list of home-manager options for zsh can be found [https://rycee.gitlab.io/home-manager/options.html#opt-wayland.windowManager.sway.enable here.]
Full list of home-manager options for zsh can be found [https://nix-community.github.io/home-manager/options.xhtml#opt-programs.zsh.enable here.]


=== Example Configuration ===
=== Example Configuration ===
Line 15: Line 15:
programs.zsh = {
programs.zsh = {
   enable = true;
   enable = true;
  enableCompletion = true;
  autosuggestions.enable = true;
  syntaxHighlighting.enable = true;
   shellAliases = {
   shellAliases = {
     ll = "ls -l";
     ll = "ls -l";
     update = "sudo nixos-rebuild switch";
     update = "sudo nixos-rebuild switch";
   };
   };
   history = {
   history.size = 10000;
    size = 10000;
  history.path = "${config.xdg.dataHome}/zsh/history";
    path = "${config.xdg.dataHome}/zsh/history";
  };
};
};
</nowiki>}}
</nowiki>}}
Line 43: Line 45:
</nowiki>}}
</nowiki>}}
==== Oh-My-Zsh ====
==== Oh-My-Zsh ====
{{file|~/.config/nixpkgs/home.nix|nix|<nowiki>
<code>oh-my-zsh</code> is a framework to manage your ZSH configuration including completion scripts for several CLI tools or custom prompt themes. It is documented in the [https://nixos.org/manual/nixos/stable/#module-programs-zsh-ohmyzsh NixOS manual].{{file|~/.config/nixpkgs/home.nix|nix|<nowiki>
programs.zsh = {
programs.zsh = {
   ... # Your zsh config
   ... # Your zsh config
   oh-my-zsh = {
   ohMyZsh = {
     enable = true;
     enable = true;
     plugins = [ "git" "thefuck" ];
     plugins = [ "git" "thefuck" ];
     theme = "robbyrussel";
     theme = "robbyrussell";
   };
   };
};
};
</nowiki>}}
</nowiki>}}
==== Manual ====
==== Manual ====
{{file|~/.config/nixpkgs/home.nix|nix|<nowiki>
{{file|~/.config/nixpkgs/home.nix|nix|<nowiki>
Line 81: Line 84:
};
};
</nowiki>}}
</nowiki>}}
== Troubleshooting ==
=== 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}})
<syntaxhighlight lang="bash">
bindkey "''${key[Up]}" up-line-or-search
</syntaxhighlight>
=== 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:
<syntaxhighlight lang="nix">
sha256 = lib.fakeSha256;
</syntaxhighlight>
This will print a valid SHA to the console and then can be used as final value for the sha256 field.
Redoing this is mandatory if one wants to update to a newer commit of the targeted plugin repository.
=== 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.
<syntaxhighlight lang="nix">
users.defaultUserShell = pkgs.zsh;
</syntaxhighlight>
To add the zsh package to /etc/shells you must update environment.shells.
<syntaxhighlight lang="nix">
environment.shells = with pkgs; [ zsh ];
</syntaxhighlight>
== See also ==
* [[Command Shell]]
[[Category:Shell]]
[[Category:NixOS Manual]]
trusted
596

edits