aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorRobert Helgesson <robert@rycee.net>2020-02-20 00:16:01 +0100
committerRobert Helgesson <robert@rycee.net>2020-02-20 00:16:01 +0100
commit543118ac703d8ea83714dd9c0c2b8041067552dd (patch)
tree8649ab863bbf9d5c9a43766127e24da2a66074ab /modules
parent57bd27b3e7277c9c487ac2e985bab1b9e5e591a3 (diff)
fish: apply nixfmt
Diffstat (limited to 'modules')
-rw-r--r--modules/programs/fish.nix203
1 files changed, 97 insertions, 106 deletions
diff --git a/modules/programs/fish.nix b/modules/programs/fish.nix
index 38a51c74fa6..bc8003f3281 100644
--- a/modules/programs/fish.nix
+++ b/modules/programs/fish.nix
@@ -36,9 +36,7 @@ let
aliasesStr = concatStringsSep "\n"
(mapAttrsToList (k: v: "alias ${k} ${escapeShellArg v}") cfg.shellAliases);
-in
-
-{
+in {
options = {
programs.fish = {
enable = mkEnableOption "fish, the friendly interactive shell";
@@ -55,7 +53,10 @@ in
shellAliases = mkOption {
type = with types; attrsOf str;
default = { };
- example = { ".." = "cd .."; ll = "ls -l"; };
+ example = {
+ ".." = "cd ..";
+ ll = "ls -l";
+ };
description = ''
An attribute set that maps aliases (the top level attribute names
in this option) to command strings or directly to build outputs.
@@ -158,44 +159,37 @@ in
};
- config = mkIf cfg.enable (mkMerge [{
+ config = mkIf cfg.enable (mkMerge [
+ {
+ home.packages = [ cfg.package ];
- home.packages = [ cfg.package ];
-
- xdg.dataFile."fish/home-manager_generated_completions".source =
- let
+ 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 ? ""
- , ...
- }:
+ 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"
- {
+ args = removeAttrs args_ [ "name" "postBuild" ] // {
+ # pass the defaults
+ inherit preferLocalBuild allowSubstitutes;
+ };
+ 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 \
@@ -203,101 +197,98 @@ in
> /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
- '';
-
- xdg.configFile."fish/config.fish".text = ''
- # ~/.config/fish/config.fish: DO NOT EDIT -- this file has been generated
- # automatically by home-manager.
+ 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);
+ };
- # if we haven't sourced the general config, do it
- if not set -q __fish_general_config_sourced
+ 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
+ '';
- set -p fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions
- fenv source ${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh > /dev/null
- set -e fish_function_path[1]
+ xdg.configFile."fish/config.fish".text = ''
+ # ~/.config/fish/config.fish: DO NOT EDIT -- this file has been generated
+ # automatically by home-manager.
- ${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
+ # if we haven't sourced the general config, do it
+ if not set -q __fish_general_config_sourced
- end
+ set -p fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions
+ fenv source ${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh > /dev/null
+ set -e fish_function_path[1]
- # if we haven't sourced the login config, do it
- status --is-login; and not set -q __fish_login_config_sourced
- and begin
+ ${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
- # Login shell initialisation
- ${cfg.loginShellInit}
+ end
- # 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
+ # if we haven't sourced the login config, do it
+ status --is-login; and not set -q __fish_login_config_sourced
+ and begin
- end
+ # Login shell initialisation
+ ${cfg.loginShellInit}
- # if we haven't sourced the interactive config, do it
- status --is-interactive; and not set -q __fish_interactive_config_sourced
- and begin
+ # 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
- # Abbreviations
- ${abbrsStr}
+ end
- # Aliases
- ${aliasesStr}
+ # if we haven't sourced the interactive config, do it
+ status --is-interactive; and not set -q __fish_interactive_config_sourced
+ and begin
- # Prompt initialisation
- ${cfg.promptInit}
+ # Abbreviations
+ ${abbrsStr}
- # Interactive shell intialisation
- ${cfg.interactiveShellInit}
+ # Aliases
+ ${aliasesStr}
- # 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
+ # Prompt initialisation
+ ${cfg.promptInit}
- end
- '';
+ # Interactive shell intialisation
+ ${cfg.interactiveShellInit}
- } {
+ # 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
+ end
+ '';
+ }
+ {
xdg.configFile = mapAttrs' (fName: fBody: {
name = "fish/functions/${fName}.fish";
- value = {"text" = ''
- function ${fName}
- ${fBody}
- end
- '';};
+ value = {
+ "text" = ''
+ function ${fName}
+ ${fBody}
+ end
+ '';
+ };
}) cfg.functions;
-
- }
+ }
# Each plugin gets a corresponding conf.d/plugin-NAME.fish file to load
# in the paths and any initialization scripts.
(mkIf (length cfg.plugins > 0) {
- xdg.configFile = mkMerge (
- (map (plugin: { "fish/conf.d/plugin-${plugin.name}.fish".text = ''
+ xdg.configFile = mkMerge ((map (plugin: {
+ "fish/conf.d/plugin-${plugin.name}.fish".text = ''
# Plugin ${plugin.name}
set -l plugin_dir ${plugin.src}
@@ -323,7 +314,7 @@ in
source $plugin_dir/init.fish
end
'';
- }) cfg.plugins));
+ }) cfg.plugins));
})
]);
}