I’m looking for some guidance on how to make a Fish function load automatically when I open my terminal. Currently, I have to manually invoke the function each time, which can be quite tedious.
Here’s the relevant part of my configuration file:
fish = {
enable = true;
shellAliases = {
ll = "eza -l";
la = "eza -a";
ls = "eza";
tree = "eza --tree";
fetch = "clear && fastfetch";
".." = "cd ..";
nfu = "cd /etc/nixos/ || exit && nix flake update";
nrs = "cd /etc/nixos/ || exit && doas nixos-rebuild switch --flake .";
nso = "cd /etc/nixos/ || exit && nix store optimise";
ncg = "cd /etc/nixos/ || exit && doas nix-collect-garbage --delete-older-than 3d";
hms = "cd /etc/nixos/ || exit && home-manager switch --flake .";
#unx = "cd /etc/nixos/ || exit && nix flake update && doas nixos-rebuild switch --flake . && home-manager switch --flake . && nix store optimise && doas nix-collect-garbage --delete-older-than 3d";
ttm = "tt -quotes en -theme catppuccin-mocha";
cat = "bat";
cd = "z";
syn = "rsync -a /etc/nixos /home/user/Documents/";
bak = "cd /home/user/Documents/nixos/ || exit && git add . && git commit -m \"Backup commit\" && git push codeberg master";
};
functions = {
unx = ''
function unx
set -l skip_flake_update 0
set -l skip_nixos_rebuild 0
set -l skip_home_manager 0
set -l skip_optimize 0
set -l skip_garbage 0
function _unx_show_help --description "Show usage for unx"
echo "Usage: unx [-s|--skip <commands>] [options]"
echo ""
echo "Options:"
echo " -s, --skip <commands> Skip the specified commands."
echo " Commands:"
echo " f Skip flake update"
echo " r Skip NixOS rebuild"
echo " h Skip home manager"
echo " o Skip optimization"
echo " g Skip garbage collection"
echo " -h, --help Show this help message."
echo ""
echo "If no options are provided, all commands will be executed."
end
set -l skip_mode 0
set -l i 1
while test $i -le (count $argv)
set -l arg $argv[$i]
switch $arg
case '-h' '--help'
_unx_show_help
return
case '-s' '--skip'
set skip_mode 1
set i (math $i + 1)
while test $i -le (count $argv)
switch $argv[$i]
case 'f'
set skip_flake_update 1
case 'r'
set skip_nixos_rebuild 1
case 'h'
set skip_home_manager 1
case 'o'
set skip_optimize 1
case 'g'
set skip_garbage 1
case '*'
_unx_show_help
return 1
end
set i (math $i + 1)
end
break
case '*'
_unx_show_help
return 1
end
set i (math $i + 1)
end
cd /etc/nixos/ || return
if test $skip_flake_update -eq 0
nix flake update
end
if test $skip_nixos_rebuild -eq 0
doas nixos-rebuild switch --flake .
end
if test $skip_home_manager -eq 0
home-manager switch --flake .
end
if test $skip_optimize -eq 0
nix store optimise
end
if test $skip_garbage -eq 0
doas nix-collect-garbage --delete-older-than 3d
end
end
'';
};
interactiveShellInit = ''
set fish_greeting # Disable greeting
'';
};
The function I want to load automatically is unx
. Does anyone know how to configure this in my NixOS setup so that it loads every time I start a new terminal session? I want it to basically work as an alias if possible, where it is already saved so no need to type it once. Realize it’s not loaded because it didn’t do anything, and do it again for it to actually run.
Any help would be greatly appreciated!
Thank you!