Fish: Difference between revisions
imported>Haemeah m add link to home-manager options list |
imported>Haemeah m better link for option reference |
||
Line 70: | Line 70: | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Full list of home-manager options for fish can be found [https://nix-community | Full list of home-manager options for fish can be found See also [https://github.com/nix-community/home-manager/blob/master/modules/programs/fish.nix here]. | ||
See [https://search.nixos.org/packages?channel=unstable&from=0&size=50&buckets=%7B%22package_attr_set%22%3A%5B%22fishPlugins%22%5D%2C%22package_license_set%22%3A%5B%5D%2C%22package_maintainers_set%22%3A%5B%5D%2C%22package_platforms%22%3A%5B%5D%7D&sort=relevance&query=fishPlugins fishPlugins package set] for available plugins in nixpkgs. | See [https://search.nixos.org/packages?channel=unstable&from=0&size=50&buckets=%7B%22package_attr_set%22%3A%5B%22fishPlugins%22%5D%2C%22package_license_set%22%3A%5B%5D%2C%22package_maintainers_set%22%3A%5B%5D%2C%22package_platforms%22%3A%5B%5D%7D&sort=relevance&query=fishPlugins fishPlugins package set] for available plugins in nixpkgs. |
Revision as of 13:02, 23 January 2024
fish, the Friendly Interactive Shell, is a command shell designed around user-friendliness.
Installation
For setting fish as the default shell system wide, see Command Shell#Changing default shell.
A basic user-specific installation with Home Manager may look like this:
home-manager.users.myuser = {
programs.fish.enable = true;
};
Change myuser
to the username of the user you want to configure.
You can enable the fish shell and manage fish configuration and plugins with Home Manager, but to enable vendor fish completions provided by Nixpkgs you will also want to enable the fish shell in /etc/nixos/configuration.nix
:
programs.fish.enable = true;
Configuration
System wide
To enable fish plugins, add your preferred plugins to `environment.systemPackages`:
environment.systemPackages = with pkgs; [
fishPlugins.done
fishPlugins.fzf-fish
fishPlugins.forgit
fishPlugins.hydro
fzf
fishPlugins.grc
grc
];
programs.fish.enable = true;
Home Manager
An example configuration in Home Manager for adding plugins and changing options could look like this:
home-manager.users.myuser = {
programs.fish = {
enable = true;
interactiveShellInit = ''
set fish_greeting # Disable greeting
'';
plugins = [
# Enable a plugin (here grc for colorized command output) from nixpkgs
{ name = "grc"; src = pkgs.fishPlugins.grc.src; }
# Manually packaging and enable a plugin
{
name = "z";
src = pkgs.fetchFromGitHub {
owner = "jethrokuan";
repo = "z";
rev = "e0e1b9dfdba362f8ab1ae8c1afc7ccf62b89f7eb";
sha256 = "0dbnir6jbwjpjalz14snzd3cgdysgcs3raznsijd6savad3qhijc";
};
}
];
};
};
Full list of home-manager options for fish can be found See also here.
See fishPlugins package set for available plugins in nixpkgs.
Useful scripts
Show that you are in a nix-shell
Add this to the fish_prompt
function (usually placed in ~/.config/fish/functions/fish_prompt.fish
):
set -l nix_shell_info (
if test -n "$IN_NIX_SHELL"
echo -n "<nix-shell> "
end
)
and $nix_shell_info
to the echo in that function, e.g.:
echo -n -s "$nix_shell_info ~>"
Now your prompt looks like this:
- outside:
~>
- inside:
<nix-shell> ~>
You can directly start nix-shell in fish with nix-shell --run fish
.
Environments
Here are some examples of helper functions that put you in a nix-shell with the given packages installed.
You can either put these in programs.fish.functions
with home-manager or in ~/.config/fish/functions/fish_prompt.fish
without.
haskellEnv
function haskellEnv
nix-shell -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [ $argv ])"
end
# Invocation: haskellEnv package1 packages2 .. packageN
pythonEnv
function pythonEnv --description 'start a nix-shell with the given python packages' --argument pythonVersion
if set -q argv[2]
set argv $argv[2..-1]
end
for el in $argv
set ppkgs $ppkgs "python"$pythonVersion"Packages.$el"
end
nix-shell -p $ppkgs
end
# Invocation: pythonEnv 3 package1 package2 .. packageN
# or: pythonEnv 2 ..