mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
fish: support flexible abbreviations
https://github.com/fish-shell/fish-shell/releases/tag/3.6.0
This commit is contained in:
parent
e1f3b36ab0
commit
8cedd63eed
3 changed files with 144 additions and 8 deletions
|
|
@ -138,9 +138,76 @@ let
|
|||
};
|
||||
};
|
||||
|
||||
abbrsStr = concatStringsSep "\n"
|
||||
(mapAttrsToList (k: v: "abbr --add --global -- ${k} ${escapeShellArg v}")
|
||||
cfg.shellAbbrs);
|
||||
abbrModule = types.submodule {
|
||||
options = {
|
||||
expansion = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
description = ''
|
||||
The command expanded by an abbreviation.
|
||||
'';
|
||||
};
|
||||
|
||||
position = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
example = "anywhere";
|
||||
description = ''
|
||||
If the position is "command", the abbreviation expands only if
|
||||
the position is a command. If it is "anywhere", the abbreviation
|
||||
expands anywhere.
|
||||
'';
|
||||
};
|
||||
|
||||
regex = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
description = ''
|
||||
The regular expression pattern matched instead of the literal name.
|
||||
'';
|
||||
};
|
||||
|
||||
setCursor = mkOption {
|
||||
type = with types; (either bool str);
|
||||
default = false;
|
||||
description = ''
|
||||
The marker indicates the position of the cursor when the abbreviation
|
||||
is expanded. When setCursor is true, the marker is set with a default
|
||||
value of "%".
|
||||
'';
|
||||
};
|
||||
|
||||
function = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
description = ''
|
||||
The fish function expanded instead of a literal string.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
abbrsStr = concatStringsSep "\n" (mapAttrsToList (name: def:
|
||||
let
|
||||
mods = with def;
|
||||
cli.toGNUCommandLineShell {
|
||||
mkOption = k: v:
|
||||
if v == null then
|
||||
[ ]
|
||||
else if k == "set-cursor" then
|
||||
[ "--${k}=${lib.generators.mkValueStringDefault { } v}" ]
|
||||
else [
|
||||
"--${k}"
|
||||
(lib.generators.mkValueStringDefault { } v)
|
||||
];
|
||||
} {
|
||||
inherit position regex function;
|
||||
set-cursor = setCursor;
|
||||
};
|
||||
modifiers = if isAttrs def then mods else "";
|
||||
expansion = if isAttrs def then def.expansion else def;
|
||||
in "abbr --add ${modifiers} -- ${name}"
|
||||
+ optionalString (expansion != null) " \"${expansion}\"") cfg.shellAbbrs);
|
||||
|
||||
aliasesStr = concatStringsSep "\n"
|
||||
(mapAttrsToList (k: v: "alias ${k} ${escapeShellArg v}") cfg.shellAliases);
|
||||
|
|
@ -199,12 +266,18 @@ in {
|
|||
};
|
||||
|
||||
shellAbbrs = mkOption {
|
||||
type = with types; attrsOf str;
|
||||
type = with types; attrsOf (either str abbrModule);
|
||||
default = { };
|
||||
example = {
|
||||
l = "less";
|
||||
gco = "git checkout";
|
||||
};
|
||||
example = literalExpression ''
|
||||
{
|
||||
l = "less";
|
||||
gco = "git checkout";
|
||||
"-C" = {
|
||||
position = "anywhere";
|
||||
expansion = "--color";
|
||||
};
|
||||
}
|
||||
'';
|
||||
description = ''
|
||||
An attribute set that maps aliases (the top level attribute names
|
||||
in this option) to abbreviations. Abbreviations are expanded with
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue