1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 03:29:45 +01:00

fish: apply nixfmt

This commit is contained in:
Robert Helgesson 2020-02-20 00:16:01 +01:00
parent 57bd27b3e7
commit 543118ac70
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
2 changed files with 97 additions and 107 deletions

1
format
View file

@ -39,7 +39,6 @@ find . -name '*.nix' \
! -path ./modules/programs/bash.nix \ ! -path ./modules/programs/bash.nix \
! -path ./modules/programs/emacs.nix \ ! -path ./modules/programs/emacs.nix \
! -path ./modules/programs/firefox.nix \ ! -path ./modules/programs/firefox.nix \
! -path ./modules/programs/fish.nix \
! -path ./modules/programs/gpg.nix \ ! -path ./modules/programs/gpg.nix \
! -path ./modules/programs/lesspipe.nix \ ! -path ./modules/programs/lesspipe.nix \
! -path ./modules/programs/neovim.nix \ ! -path ./modules/programs/neovim.nix \

View file

@ -36,9 +36,7 @@ let
aliasesStr = concatStringsSep "\n" aliasesStr = concatStringsSep "\n"
(mapAttrsToList (k: v: "alias ${k} ${escapeShellArg v}") cfg.shellAliases); (mapAttrsToList (k: v: "alias ${k} ${escapeShellArg v}") cfg.shellAliases);
in in {
{
options = { options = {
programs.fish = { programs.fish = {
enable = mkEnableOption "fish, the friendly interactive shell"; enable = mkEnableOption "fish, the friendly interactive shell";
@ -55,7 +53,10 @@ in
shellAliases = mkOption { shellAliases = mkOption {
type = with types; attrsOf str; type = with types; attrsOf str;
default = { }; default = { };
example = { ".." = "cd .."; ll = "ls -l"; }; example = {
".." = "cd ..";
ll = "ls -l";
};
description = '' description = ''
An attribute set that maps aliases (the top level attribute names An attribute set that maps aliases (the top level attribute names
in this option) to command strings or directly to build outputs. 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 # paths later in the list will overwrite those already linked
destructiveSymlinkJoin = destructiveSymlinkJoin = args_@{ name, paths, preferLocalBuild ? true
args_@{ name , allowSubstitutes ? false, postBuild ? "", ... }:
, paths
, preferLocalBuild ? true
, allowSubstitutes ? false
, postBuild ? ""
, ...
}:
let let
args = removeAttrs args_ [ "name" "postBuild" ] args = removeAttrs args_ [ "name" "postBuild" ] // {
// { inherit preferLocalBuild allowSubstitutes; }; # pass the defaults # pass the defaults
in pkgs.runCommand name args inherit preferLocalBuild allowSubstitutes;
'' };
mkdir -p $out in pkgs.runCommand name args ''
for i in $paths; do mkdir -p $out
if [ -z "$(find $i -prune -empty)" ]; then for i in $paths; do
cp -srf $i/* $out if [ -z "$(find $i -prune -empty)" ]; then
fi cp -srf $i/* $out
done fi
${postBuild} done
''; ${postBuild}
generateCompletions = package: pkgs.runCommand '';
"${package.name}-fish-completions"
{ generateCompletions = package:
pkgs.runCommand "${package.name}-fish-completions" {
src = package; src = package;
nativeBuildInputs = [ pkgs.python2 ]; nativeBuildInputs = [ pkgs.python2 ];
buildInputs = [ cfg.package ]; buildInputs = [ cfg.package ];
preferLocalBuild = true; preferLocalBuild = true;
allowSubstitutes = false; allowSubstitutes = false;
} } ''
''
mkdir -p $out mkdir -p $out
if [ -d $src/share/man ]; then if [ -d $src/share/man ]; then
find $src/share/man -type f \ find $src/share/man -type f \
@ -203,101 +197,98 @@ in
> /dev/null > /dev/null
fi fi
''; '';
in in destructiveSymlinkJoin {
destructiveSymlinkJoin { name = "${config.home.username}-fish-completions";
name = "${config.home.username}-fish-completions"; paths =
paths = let cmp = (a: b: (a.meta.priority or 0) > (b.meta.priority or 0));
let in map generateCompletions (sort cmp config.home.packages);
cmp = (a: b: (a.meta.priority or 0) > (b.meta.priority or 0)); };
in
map generateCompletions (sort cmp config.home.packages);
};
programs.fish.interactiveShellInit = '' programs.fish.interactiveShellInit = ''
# add completions generated by Home Manager to $fish_complete_path # add completions generated by Home Manager to $fish_complete_path
begin begin
set -l joined (string join " " $fish_complete_path) set -l joined (string join " " $fish_complete_path)
set -l prev_joined (string replace --regex "[^\s]*generated_completions.*" "" $joined) set -l prev_joined (string replace --regex "[^\s]*generated_completions.*" "" $joined)
set -l post_joined (string replace $prev_joined "" $joined) set -l post_joined (string replace $prev_joined "" $joined)
set -l prev (string split " " (string trim $prev_joined)) set -l prev (string split " " (string trim $prev_joined))
set -l post (string split " " (string trim $post_joined)) set -l post (string split " " (string trim $post_joined))
set fish_complete_path $prev "${config.xdg.dataHome}/fish/home-manager_generated_completions" $post set fish_complete_path $prev "${config.xdg.dataHome}/fish/home-manager_generated_completions" $post
end end
''; '';
xdg.configFile."fish/config.fish".text = '' xdg.configFile."fish/config.fish".text = ''
# ~/.config/fish/config.fish: DO NOT EDIT -- this file has been generated # ~/.config/fish/config.fish: DO NOT EDIT -- this file has been generated
# automatically by home-manager. # automatically by home-manager.
# if we haven't sourced the general config, do it # if we haven't sourced the general config, do it
if not set -q __fish_general_config_sourced if not set -q __fish_general_config_sourced
set -p fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions 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 fenv source ${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh > /dev/null
set -e fish_function_path[1] set -e fish_function_path[1]
${cfg.shellInit} ${cfg.shellInit}
# and leave a note so we don't source this config section again from # and leave a note so we don't source this config section again from
# this very shell (children will source the general config anew) # this very shell (children will source the general config anew)
set -g __fish_general_config_sourced 1 set -g __fish_general_config_sourced 1
end end
# if we haven't sourced the login config, do it # if we haven't sourced the login config, do it
status --is-login; and not set -q __fish_login_config_sourced status --is-login; and not set -q __fish_login_config_sourced
and begin and begin
# Login shell initialisation # Login shell initialisation
${cfg.loginShellInit} ${cfg.loginShellInit}
# and leave a note so we don't source this config section again from # and leave a note so we don't source this config section again from
# this very shell (children will source the general config anew) # this very shell (children will source the general config anew)
set -g __fish_login_config_sourced 1 set -g __fish_login_config_sourced 1
end end
# if we haven't sourced the interactive config, do it # if we haven't sourced the interactive config, do it
status --is-interactive; and not set -q __fish_interactive_config_sourced status --is-interactive; and not set -q __fish_interactive_config_sourced
and begin and begin
# Abbreviations # Abbreviations
${abbrsStr} ${abbrsStr}
# Aliases # Aliases
${aliasesStr} ${aliasesStr}
# Prompt initialisation # Prompt initialisation
${cfg.promptInit} ${cfg.promptInit}
# Interactive shell intialisation # Interactive shell intialisation
${cfg.interactiveShellInit} ${cfg.interactiveShellInit}
# and leave a note so we don't source this config section again from # and leave a note so we don't source this config section again from
# this very shell (children will source the general config anew, # this very shell (children will source the general config anew,
# allowing configuration changes in, e.g, aliases, to propagate) # allowing configuration changes in, e.g, aliases, to propagate)
set -g __fish_interactive_config_sourced 1 set -g __fish_interactive_config_sourced 1
end
'';
} {
end
'';
}
{
xdg.configFile = mapAttrs' (fName: fBody: { xdg.configFile = mapAttrs' (fName: fBody: {
name = "fish/functions/${fName}.fish"; name = "fish/functions/${fName}.fish";
value = {"text" = '' value = {
function ${fName} "text" = ''
${fBody} function ${fName}
end ${fBody}
'';}; end
'';
};
}) cfg.functions; }) cfg.functions;
}
}
# Each plugin gets a corresponding conf.d/plugin-NAME.fish file to load # Each plugin gets a corresponding conf.d/plugin-NAME.fish file to load
# in the paths and any initialization scripts. # in the paths and any initialization scripts.
(mkIf (length cfg.plugins > 0) { (mkIf (length cfg.plugins > 0) {
xdg.configFile = mkMerge ( xdg.configFile = mkMerge ((map (plugin: {
(map (plugin: { "fish/conf.d/plugin-${plugin.name}.fish".text = '' "fish/conf.d/plugin-${plugin.name}.fish".text = ''
# Plugin ${plugin.name} # Plugin ${plugin.name}
set -l plugin_dir ${plugin.src} set -l plugin_dir ${plugin.src}
@ -323,7 +314,7 @@ in
source $plugin_dir/init.fish source $plugin_dir/init.fish
end end
''; '';
}) cfg.plugins)); }) cfg.plugins));
}) })
]); ]);
} }