1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-09 02:21:05 +01:00
home-manager/tests/modules/programs/fish/abbrs.nix
Karun Sandhu 8675edf7d3
fish: add command option for abbreviations (#6666)
The fish shell has added a flag to the abbr command which allows one to expand it only if it is typed after a real command e.g.:
git s -> git status
s -> s

Also see the last example here: https://fishshell.com/docs/current/cmds/abbr.html#examples
2025-03-19 22:43:42 -05:00

78 lines
2.3 KiB
Nix

{ config, ... }: {
config = {
programs.fish = {
enable = true;
shellAbbrs = {
l = "less";
gco = "git checkout";
"-C" = {
position = "anywhere";
expansion = "--color";
};
L = {
position = "anywhere";
setCursor = true;
expansion = "% | less";
};
"!!" = {
position = "anywhere";
function = "last_history_item";
};
vim_edit_texts = {
position = "command";
regex = ".+\\.txt";
function = "vim_edit";
};
"4DIRS" = {
setCursor = "!";
expansion = ''
for dir in */
cd $dir
!
cd ..
end
'';
};
co = {
command = "git";
expansion = "checkout";
};
dotdot = {
regex = "^\\.\\.+$";
function = "multicd";
};
};
};
nmt = {
description =
"if fish.shellAbbrs is set, check fish.config contains valid abbreviations";
script = ''
assertFileContains home-files/.config/fish/config.fish \
"abbr --add -- l less"
assertFileContains home-files/.config/fish/config.fish \
"abbr --add -- gco 'git checkout'"
assertFileContains home-files/.config/fish/config.fish \
"abbr --add --position anywhere -- -C --color"
assertFileContains home-files/.config/fish/config.fish \
"abbr --add --position anywhere --set-cursor -- L '% | less'"
assertFileContains home-files/.config/fish/config.fish \
"abbr --add --function last_history_item --position anywhere -- !!"
assertFileContains home-files/.config/fish/config.fish \
"abbr --add --function vim_edit --position command --regex '.+\.txt' -- vim_edit_texts"
assertFileContains home-files/.config/fish/config.fish \
"abbr --add '--set-cursor=!' -- 4DIRS 'for dir in */
cd \$dir
!
cd ..
end
'"
assertFileContains home-files/.config/fish/config.fish \
"abbr --add --command git -- co checkout"
assertFileContains home-files/.config/fish/config.fish \
"abbr --add --function multicd --regex '^\.\.+$' -- dotdot"
'';
};
};
}