Fish: Difference between revisions

From NixOS Wiki
imported>Jtojnar
m spacing
imported>Jtojnar
modernize shell setiing
Line 10: Line 10:
   programs.fish.enable = true;
   programs.fish.enable = true;


   users.extraUsers.foo = {
   users.users.foo = {
     shell = "/run/current-system/sw/bin/fish";
     shell = pkgs.fish;
   };
   };
   ...
   ...

Revision as of 01:30, 17 April 2020

fish is the Friendly Interactive SHell.

Setting fish as the login shell

The following /etc/nixos/configuration.nix fragment demonstrates how to enable fish and set it as the default shell for user foo.

{
  ...
  programs.fish.enable = true;

  users.users.foo = {
    shell = pkgs.fish;
  };
  ...
}

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> ~>

btw. you can directly start nix-shell in fish with nix-shell --run fish, but (FIXME) the normal build functions are not available there.

Environments

Helper functions that put you in a nix-shell with the given packages installed.

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 ..