Zsh: Difference between revisions

From NixOS Wiki
imported>Flexagoon
(Create a zsh page)
 
imported>Flexagoon
No edit summary
Line 4: Line 4:


== Installation ==
== Installation ==
 
See [[Command Shell#Changing Default Shell]].
=== Globally ===
To set zsh as your default shell system-wide, add the following line to your config:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
users.defaultUserShell = pkgs.zsh;
</nowiki>}}
then run {{ic|nixos-rebuild switch}} and reboot your system.
=== For one user only ===
To only set zsh as a default shell for one of the users, add
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
shell = pkgs.zsh;
</nowiki>}}
to this user's section like so:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
users.users.yourname = {}
  ... # Your user configuration
  shell = pkgs.zsh;
};
</nowiki>}}


== Configuration ==
== Configuration ==

Revision as of 05:29, 12 June 2021

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 emulate sh), it offers advantages such as improved tab completion and globbing.

The Zsh FAQ offers more reasons to use Zsh.

Installation

See Command Shell#Changing Default Shell.

Configuration

Zsh can be configured with Home Manager.

Full list of home-manager options for zsh can be found here.

Example Configuration

~/.config/nixpkgs/home.nix
programs.zsh = {
  enable = true;
  shellAliases = {
    ll = "ls -l";
    update = "sudo nixos-rebuild switch";
  };
  history = {
    size = 10000;
    path = "${config.xdg.dataHome}/zsh/history";
  };
};

Plugin Management

Home manager has three ways of managing plugins: Zplug, Oh-My-Zsh and manual.

Zplug

~/.config/nixpkgs/home.nix
programs.zsh = {
  ... # Your zsh config
  zplug = {
    enable = true;
    plugins = [
      { name = "zsh-users/zsh-autosuggestions"; } # Simple plugin installation
      { name = "romkatv/powerlevel10k"; tags = [ as:theme depth:1 ]; } # Installations with additional options. For the list of options, please refer to Zplug README.
    ];
  };
};

Oh-My-Zsh

~/.config/nixpkgs/home.nix
programs.zsh = {
  ... # Your zsh config
  oh-my-zsh = {
    enable = true;
    plugins = [ "git" "thefuck" ];
    theme = "robbyrussel";
  };
};

Manual

~/.config/nixpkgs/home.nix
programs.zsh = {
  ... # Your zsh config
  plugins = [
    {
      # will source zsh-autosuggestions.plugin.zsh
      name = "zsh-autosuggestions";
      src = pkgs.fetchFromGitHub {
        owner = "zsh-users";
        repo = "zsh-autosuggestions";
        rev = "v0.4.0";
        sha256 = "0z6i9wjjklb4lvr7zjhbphibsyx51psv50gm07mbb0kj9058j6kc";
      };
    }
    {
      name = "enhancd";
      file = "init.sh";
      src = pkgs.fetchFromGitHub {
        owner = "b4b4r07";
        repo = "enhancd";
        rev = "v2.2.1";
        sha256 = "0iqa9j09fwm6nj5rpip87x3hnvbbz9w9ajgm6wkrd5fls8fn8i5g";
      };
    }
  ];
};