2018-08-14 07:39:22 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.fish;
|
|
|
|
|
2019-09-24 08:16:49 +00:00
|
|
|
pluginModule = types.submodule ({ config, ... }: {
|
|
|
|
options = {
|
|
|
|
src = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description = ''
|
|
|
|
Path to the plugin folder.
|
|
|
|
</para><para>
|
|
|
|
Relevant pieces will be added to the fish function path and
|
|
|
|
the completion path. The <filename>init.fish</filename> and
|
|
|
|
<filename>key_binding.fish</filename> files are sourced if
|
|
|
|
they exist.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The name of the plugin.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-02-14 21:36:44 +00:00
|
|
|
abbrsStr = concatStringsSep "\n"
|
|
|
|
(mapAttrsToList (k: v: "abbr --add --global -- ${k} ${escapeShellArg v}")
|
|
|
|
cfg.shellAbbrs);
|
2018-08-14 07:39:22 +00:00
|
|
|
|
2020-02-14 21:36:44 +00:00
|
|
|
aliasesStr = concatStringsSep "\n"
|
|
|
|
(mapAttrsToList (k: v: "alias ${k} ${escapeShellArg v}") cfg.shellAliases);
|
2018-08-14 07:39:22 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
programs.fish = {
|
2019-09-24 05:13:02 +00:00
|
|
|
enable = mkEnableOption "fish, the friendly interactive shell";
|
2018-08-14 07:39:22 +00:00
|
|
|
|
2018-12-17 11:57:30 +00:00
|
|
|
package = mkOption {
|
2019-09-23 06:53:08 +00:00
|
|
|
type = types.package;
|
2018-12-17 11:57:30 +00:00
|
|
|
default = pkgs.fish;
|
2019-08-27 22:12:28 +00:00
|
|
|
defaultText = literalExample "pkgs.fish";
|
2018-12-17 11:57:30 +00:00
|
|
|
description = ''
|
|
|
|
The fish package to install. May be used to change the version.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-08-14 07:39:22 +00:00
|
|
|
shellAliases = mkOption {
|
2019-09-24 05:05:21 +00:00
|
|
|
type = with types; attrsOf str;
|
2018-08-14 07:39:22 +00:00
|
|
|
default = {};
|
2019-09-23 06:54:08 +00:00
|
|
|
example = { ".." = "cd .."; ll = "ls -l"; };
|
2018-08-14 07:39:22 +00:00
|
|
|
description = ''
|
2019-09-23 07:01:09 +00:00
|
|
|
An attribute set that maps aliases (the top level attribute names
|
|
|
|
in this option) to command strings or directly to build outputs.
|
2018-08-14 07:39:22 +00:00
|
|
|
'';
|
|
|
|
};
|
2018-09-09 19:17:49 +00:00
|
|
|
|
2018-08-14 07:39:22 +00:00
|
|
|
shellAbbrs = mkOption {
|
2019-09-24 05:05:21 +00:00
|
|
|
type = with types; attrsOf str;
|
2018-08-14 07:39:22 +00:00
|
|
|
default = {};
|
2019-09-23 06:54:08 +00:00
|
|
|
example = { l = "less"; gco = "git checkout"; };
|
2018-08-14 07:39:22 +00:00
|
|
|
description = ''
|
2019-09-23 07:01:09 +00:00
|
|
|
An attribute set that maps aliases (the top level attribute names
|
|
|
|
in this option) to abbreviations. Abbreviations are expanded with
|
|
|
|
the longer phrase after they are entered.
|
2018-08-14 07:39:22 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
shellInit = mkOption {
|
2019-09-23 06:53:08 +00:00
|
|
|
type = types.lines;
|
2018-08-14 07:39:22 +00:00
|
|
|
default = "";
|
|
|
|
description = ''
|
2019-09-23 07:01:09 +00:00
|
|
|
Shell script code called during fish shell
|
|
|
|
initialisation.
|
2018-08-14 07:39:22 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
loginShellInit = mkOption {
|
2019-09-23 06:53:08 +00:00
|
|
|
type = types.lines;
|
2018-08-14 07:39:22 +00:00
|
|
|
default = "";
|
|
|
|
description = ''
|
2019-09-23 07:01:09 +00:00
|
|
|
Shell script code called during fish login shell
|
|
|
|
initialisation.
|
2018-08-14 07:39:22 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
interactiveShellInit = mkOption {
|
2019-09-23 06:53:08 +00:00
|
|
|
type = types.lines;
|
2018-08-14 07:39:22 +00:00
|
|
|
default = "";
|
|
|
|
description = ''
|
2019-09-23 07:01:09 +00:00
|
|
|
Shell script code called during interactive fish shell
|
|
|
|
initialisation.
|
2018-08-14 07:39:22 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
promptInit = mkOption {
|
2019-09-23 06:53:08 +00:00
|
|
|
type = types.lines;
|
2018-08-14 07:39:22 +00:00
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Shell script code used to initialise fish prompt.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2019-03-23 20:09:03 +00:00
|
|
|
|
|
|
|
programs.fish.plugins = mkOption {
|
2019-09-24 08:19:35 +00:00
|
|
|
type = types.listOf pluginModule;
|
2019-03-23 20:09:03 +00:00
|
|
|
default = [];
|
2019-09-24 08:19:35 +00:00
|
|
|
example = literalExample ''
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name = "z";
|
|
|
|
src = pkgs.fetchFromGitHub {
|
|
|
|
owner = "jethrokuan";
|
|
|
|
repo = "z";
|
|
|
|
rev = "ddeb28a7b6a1f0ec6dae40c636e5ca4908ad160a";
|
|
|
|
sha256 = "0c5i7sdrsp0q3vbziqzdyqn4fmp235ax4mn4zslrswvn8g3fvdyh";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
# oh-my-fish plugins are stored in their own repositories, which
|
|
|
|
# makes them simple to import into home-manager.
|
|
|
|
{
|
|
|
|
name = "fasd";
|
|
|
|
src = pkgs.fetchFromGitHub {
|
|
|
|
owner = "oh-my-fish";
|
|
|
|
repo = "plugin-fasd";
|
|
|
|
rev = "38a5b6b6011106092009549e52249c6d6f501fba";
|
|
|
|
sha256 = "06v37hqy5yrv5a6ssd1p3cjd9y3hnp19d3ab7dag56fs1qmgyhbs";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
]
|
|
|
|
'';
|
2019-03-23 20:09:03 +00:00
|
|
|
description = ''
|
2019-09-24 08:19:35 +00:00
|
|
|
The plugins to source in
|
|
|
|
<filename>conf.d/99plugins.fish</filename>.
|
2019-03-23 20:09:03 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
programs.fish.functions = mkOption {
|
2019-09-24 05:00:23 +00:00
|
|
|
type = types.attrsOf types.lines;
|
2019-03-23 20:09:03 +00:00
|
|
|
default = {};
|
2019-09-24 05:00:23 +00:00
|
|
|
example = { gitignore = "curl -sL https://www.gitignore.io/api/$argv"; };
|
2019-03-23 20:09:03 +00:00
|
|
|
description = ''
|
2019-09-24 05:00:23 +00:00
|
|
|
Basic functions to add to fish. For more information see
|
|
|
|
<link xlink:href="https://fishshell.com/docs/current/commands.html#function"/>.
|
2019-03-23 20:09:03 +00:00
|
|
|
'';
|
|
|
|
};
|
2019-04-12 10:33:51 +00:00
|
|
|
|
2018-08-14 07:39:22 +00:00
|
|
|
};
|
|
|
|
|
2019-03-23 20:09:03 +00:00
|
|
|
config = mkIf cfg.enable (mkMerge [{
|
2019-09-24 08:20:44 +00:00
|
|
|
|
2018-12-17 11:57:30 +00:00
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
|
|
|
xdg.dataFile."fish/home-manager_generated_completions".source =
|
|
|
|
let
|
|
|
|
# paths later in the list will overwrite those already linked
|
|
|
|
destructiveSymlinkJoin =
|
|
|
|
args_@{ name
|
|
|
|
, paths
|
|
|
|
, preferLocalBuild ? true
|
|
|
|
, allowSubstitutes ? false
|
|
|
|
, postBuild ? ""
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
args = removeAttrs args_ [ "name" "postBuild" ]
|
|
|
|
// { inherit preferLocalBuild allowSubstitutes; }; # pass the defaults
|
|
|
|
in pkgs.runCommand name args
|
|
|
|
''
|
|
|
|
mkdir -p $out
|
|
|
|
for i in $paths; do
|
|
|
|
if [ -z "$(find $i -prune -empty)" ]; then
|
|
|
|
cp -srf $i/* $out
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
${postBuild}
|
|
|
|
'';
|
|
|
|
generateCompletions = package: pkgs.runCommand
|
|
|
|
"${package.name}-fish-completions"
|
|
|
|
{
|
|
|
|
src = package;
|
|
|
|
nativeBuildInputs = [ pkgs.python2 ];
|
|
|
|
buildInputs = [ cfg.package ];
|
|
|
|
preferLocalBuild = true;
|
|
|
|
allowSubstitutes = false;
|
|
|
|
}
|
|
|
|
''
|
|
|
|
mkdir -p $out
|
|
|
|
if [ -d $src/share/man ]; then
|
|
|
|
find $src/share/man -type f \
|
|
|
|
| xargs python ${cfg.package}/share/fish/tools/create_manpage_completions.py --directory $out \
|
|
|
|
> /dev/null
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
destructiveSymlinkJoin {
|
|
|
|
name = "${config.home.username}-fish-completions";
|
|
|
|
paths =
|
|
|
|
let
|
|
|
|
cmp = (a: b: (a.meta.priority or 0) > (b.meta.priority or 0));
|
|
|
|
in
|
|
|
|
map generateCompletions (sort cmp config.home.packages);
|
|
|
|
};
|
|
|
|
|
|
|
|
programs.fish.interactiveShellInit = ''
|
|
|
|
# add completions generated by Home Manager to $fish_complete_path
|
|
|
|
begin
|
|
|
|
set -l joined (string join " " $fish_complete_path)
|
|
|
|
set -l prev_joined (string replace --regex "[^\s]*generated_completions.*" "" $joined)
|
|
|
|
set -l post_joined (string replace $prev_joined "" $joined)
|
|
|
|
set -l prev (string split " " (string trim $prev_joined))
|
|
|
|
set -l post (string split " " (string trim $post_joined))
|
|
|
|
set fish_complete_path $prev "${config.xdg.dataHome}/fish/home-manager_generated_completions" $post
|
|
|
|
end
|
|
|
|
'';
|
2018-08-14 07:39:22 +00:00
|
|
|
|
|
|
|
xdg.configFile."fish/config.fish".text = ''
|
2019-09-24 05:11:58 +00:00
|
|
|
# ~/.config/fish/config.fish: DO NOT EDIT -- this file has been generated
|
|
|
|
# automatically by home-manager.
|
|
|
|
|
2018-08-14 07:39:22 +00:00
|
|
|
# if we haven't sourced the general config, do it
|
|
|
|
if not set -q __fish_general_config_sourced
|
2019-09-24 05:11:58 +00:00
|
|
|
|
2018-09-09 12:41:36 +00:00
|
|
|
set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path
|
|
|
|
fenv source ${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh > /dev/null
|
|
|
|
set -e fish_function_path[1]
|
|
|
|
|
2018-08-14 07:39:22 +00:00
|
|
|
${cfg.shellInit}
|
|
|
|
# and leave a note so we don't source this config section again from
|
|
|
|
# this very shell (children will source the general config anew)
|
|
|
|
set -g __fish_general_config_sourced 1
|
2019-09-24 05:11:58 +00:00
|
|
|
|
2018-08-14 07:39:22 +00:00
|
|
|
end
|
2019-09-24 05:11:58 +00:00
|
|
|
|
2018-08-14 07:39:22 +00:00
|
|
|
# if we haven't sourced the login config, do it
|
|
|
|
status --is-login; and not set -q __fish_login_config_sourced
|
|
|
|
and begin
|
|
|
|
|
2019-09-24 05:11:58 +00:00
|
|
|
# Login shell initialisation
|
2018-08-14 07:39:22 +00:00
|
|
|
${cfg.loginShellInit}
|
2019-09-24 05:11:58 +00:00
|
|
|
|
2018-08-14 07:39:22 +00:00
|
|
|
# and leave a note so we don't source this config section again from
|
|
|
|
# this very shell (children will source the general config anew)
|
|
|
|
set -g __fish_login_config_sourced 1
|
2019-09-24 05:11:58 +00:00
|
|
|
|
2018-08-14 07:39:22 +00:00
|
|
|
end
|
2019-09-24 05:11:58 +00:00
|
|
|
|
2018-08-14 07:39:22 +00:00
|
|
|
# if we haven't sourced the interactive config, do it
|
|
|
|
status --is-interactive; and not set -q __fish_interactive_config_sourced
|
2018-09-09 19:17:49 +00:00
|
|
|
and begin
|
2019-09-24 05:11:58 +00:00
|
|
|
|
|
|
|
# Abbreviations
|
2018-08-14 07:39:22 +00:00
|
|
|
${abbrsStr}
|
2018-09-09 19:17:49 +00:00
|
|
|
|
2018-08-14 07:39:22 +00:00
|
|
|
# Aliases
|
|
|
|
${aliasesStr}
|
2018-09-09 19:17:49 +00:00
|
|
|
|
2019-09-24 05:11:58 +00:00
|
|
|
# Prompt initialisation
|
2018-08-14 07:39:22 +00:00
|
|
|
${cfg.promptInit}
|
2019-09-24 05:11:58 +00:00
|
|
|
|
|
|
|
# Interactive shell intialisation
|
2018-08-14 07:39:22 +00:00
|
|
|
${cfg.interactiveShellInit}
|
2019-09-24 05:11:58 +00:00
|
|
|
|
2018-08-14 07:39:22 +00:00
|
|
|
# and leave a note so we don't source this config section again from
|
|
|
|
# this very shell (children will source the general config anew,
|
|
|
|
# allowing configuration changes in, e.g, aliases, to propagate)
|
|
|
|
set -g __fish_interactive_config_sourced 1
|
2019-09-24 05:11:58 +00:00
|
|
|
|
2018-08-14 07:39:22 +00:00
|
|
|
end
|
|
|
|
'';
|
2019-09-24 08:20:44 +00:00
|
|
|
|
2019-03-23 20:09:03 +00:00
|
|
|
} {
|
2019-09-24 08:20:44 +00:00
|
|
|
|
|
|
|
xdg.configFile = mapAttrs' (fName: fBody: {
|
|
|
|
name = "fish/functions/${fName}.fish";
|
2019-09-24 05:00:23 +00:00
|
|
|
value = {"text" = ''
|
2019-09-24 08:20:44 +00:00
|
|
|
function ${fName}
|
|
|
|
${fBody}
|
2019-09-24 05:00:23 +00:00
|
|
|
end
|
|
|
|
'';};
|
|
|
|
}) cfg.functions;
|
2019-09-24 08:21:34 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-25 06:20:53 +00:00
|
|
|
# Each plugin gets a corresponding conf.d/plugin-NAME.fish file to load
|
|
|
|
# in the paths and any initialization scripts.
|
2019-09-24 08:21:34 +00:00
|
|
|
(mkIf (length cfg.plugins > 0) {
|
2019-09-25 06:20:53 +00:00
|
|
|
xdg.configFile = mkMerge (
|
|
|
|
(map (plugin: { "fish/conf.d/plugin-${plugin.name}.fish".text = ''
|
2019-09-24 08:21:34 +00:00
|
|
|
# Plugin ${plugin.name}
|
2019-09-25 06:20:53 +00:00
|
|
|
set -l plugin_dir ${plugin.src}
|
2019-09-24 08:21:34 +00:00
|
|
|
|
2019-09-25 06:20:53 +00:00
|
|
|
# Set paths to import plugin components
|
|
|
|
if test -d $plugin_dir"/functions"
|
|
|
|
set fish_function_path $fish_function_path[1] $plugin_dir"/functions" $fish_function_path[2..-1]
|
2019-09-24 08:21:34 +00:00
|
|
|
end
|
|
|
|
|
2019-09-25 06:20:53 +00:00
|
|
|
if test -d $plugin_dir"/completions"
|
|
|
|
set fish_complete_path $fish_function_path[1] $plugin_dir"/completions" $fish_complete_path[2..-1]
|
2019-09-24 08:21:34 +00:00
|
|
|
end
|
|
|
|
|
2019-09-25 06:20:53 +00:00
|
|
|
# Source initialization code if it exists.
|
|
|
|
if test -d $plugin_dir"/conf.d"
|
2020-02-08 00:15:11 +00:00
|
|
|
source $plugin_dir/conf.d/*.fish
|
2019-09-24 08:21:34 +00:00
|
|
|
end
|
|
|
|
|
2019-09-25 06:20:53 +00:00
|
|
|
if test -f $plugin_dir"/key_bindings.fish"
|
|
|
|
source $plugin_dir"/key_bindings.fish"
|
2019-09-24 08:21:34 +00:00
|
|
|
end
|
|
|
|
|
2019-09-25 06:20:53 +00:00
|
|
|
if test -f $plugin_dir"/init.fish"
|
|
|
|
source $plugin_dir"/init.fish"
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
}) cfg.plugins));
|
2019-09-24 08:21:34 +00:00
|
|
|
})
|
|
|
|
]);
|
2018-08-14 07:39:22 +00:00
|
|
|
}
|