Fish: Difference between revisions

Pigs (talk | contribs)
m NixOS System Configuration: make the nixos system configuration accomplish the same thing as the home manager example config
Pigeon (talk | contribs)
 
(11 intermediate revisions by 8 users not shown)
Line 20: Line 20:
Replace <code>myuser</code> with the appropriate username.
Replace <code>myuser</code> with the appropriate username.


{{warning| [https://fishshell.com/docs/current/index.html#default-shell As noted in the fish documentation], using fish as your *login* shell (via <code>/etc/passwd</code>) may cause issues, particularly for the <code>root</code> user, because fish is not POSIX compliant. While using fish as the default shell for regular users is generaly safe, caution is still advised. See the [[#section Setting fish as default shell|Setting fish as default shell]] section for recommendations and mitigations.}}
{{warning| [https://fishshell.com/docs/current/index.html#default-shell As noted in the fish documentation], using fish as your *login* shell (via <code>/etc/passwd</code>) may cause issues, particularly for the <code>root</code> user, because fish is not POSIX compliant. While using fish as the default shell for regular users is generaly safe, caution is still advised. See [[#Setting fish as default shell]] for recommendations and mitigations.}}


=== Home Manager ===
=== Home Manager ===
Line 70: Line 70:
     fishPlugins.grc
     fishPlugins.grc
     grc
     grc
    # Use 3rd-party fish plugins manually packaged.
    (pkgs.callPackage ../fish-colored-man.nix {buildFishPlugin = pkgs.fishPlugins.buildFishPlugin; } )
   ];
   ];
</nowiki>
|name=/etc/nixos/configuration.nix|lang=nix}}
Example of a file containing the definition of a fish plugin.
{{file|/etc/nixos/fish-colored-man.nix|nix|
<nowiki>
{
  lib,
  buildFishPlugin,
  fetchFromGitHub,
}:
buildFishPlugin {
  pname = "fish-colored-man";
  version = "0-unstable-20240416";
  src = fetchFromGitHub {
    owner = "decors";
    repo = "fish-colored-man";
    rev = "1ad8fff696d48c8bf173aa98f9dff39d7916de0e";
    hash = "sha256-uoZ4eSFbZlsRfISIkJQp24qPUNqxeD0JbRb/gVdRYlA=";
  };
}
</nowiki>
</nowiki>
}}
}}
Line 114: Line 136:


Using fish as the the login shell can cause compatibility issues. For example, certain recovery environments such as systemd's emergency mode to be completely broken when fish was set as the login shell. This  limitation is noted on the [https://wiki.gentoo.org/wiki/Fish#Caveats Gentoo] wiki. There they present an alternative, keeping bash as the system shell but having it exec fish when run interactively.
Using fish as the the login shell can cause compatibility issues. For example, certain recovery environments such as systemd's emergency mode to be completely broken when fish was set as the login shell. This  limitation is noted on the [https://wiki.gentoo.org/wiki/Fish#Caveats Gentoo] wiki. There they present an alternative, keeping bash as the system shell but having it exec fish when run interactively.
{{Expansion}}


Here is one solution, which launches fish unless the parent process is already fish:
Here is one solution, which launches fish unless the parent process is already fish:
Line 130: Line 154:
</nowiki>
</nowiki>
}}
}}
Note that if you use the copy button to the right of the above code block, there will be a unicode space before the <code>!=</code> on line 3 of the snippet that you will need to change to a non-unicode space before executing this in your shell.
'''Setting fish as default for Gnome Console'''
It is possible to set fish as the interactive non-login shell for Gnome Console without setting fish as the login shell (the login shell in /etc/passwd for your user will not be fish).
{{File|3=home-manager.users.myuser = {
    dconf = {
        enable = true;
        settings."org/gnome/Console" = {
            shell = [ "fish" ];
        };
    };
};|name=home.nix|lang=nix}}


If you still want to set fish as the login shell, see [[Command Shell#Changing the default shell]].
If you still want to set fish as the login shell, see [[Command Shell#Changing the default shell]].
==== Disable man page generation ====
Some users suffer from slow build due to fish enabling `documentation.man.generateCaches`. You may force false.
documentation.man.generateCaches = false'';''
For home-manager users, man cache need to be disabled in programs
programs.man.generateCaches = false'';''


==== Running fish interactively with zsh as system shell on darwin ====
==== Running fish interactively with zsh as system shell on darwin ====
Line 158: Line 206:
)
)
</syntaxhighlight>
</syntaxhighlight>
{{Note|This won't work with the new {{ic|nix shell}} command, as it doesn't set {{ic|IN_NIX_SHELL}} variable. You can instead check if {{ic|$SHLVL}} is {{ic|> 1}}, or check if {{ic|$PATH}} contains paths from {{ic|/nix/store}} (which get added at the beginning of the {{ic|$PATH}} when you enter nix shell). See https://github.com/NixOS/nix/issues/6677 for more context and workarounds.}}


and <code>$nix_shell_info</code> to the echo in that function, e.g.:
and <code>$nix_shell_info</code> to the echo in that function, e.g.: