Skip to content

Commit

Permalink
distrobox: add fishShellIntegration
Browse files Browse the repository at this point in the history
  • Loading branch information
aguirre-matteo committed Mar 1, 2025
1 parent c2eaf64 commit a22407c
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions modules/programs/distrobox.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,12 @@ let
read -p "Distrobox's containers list have changed. Do you want to build them now? [y/N/i]: " answer
if [[ $answer == "y" ]] || [[ $answer == "Y" ]]; then
distrobox-nixos-build
echo $new_hash > $prev_hash_file
elif [[ $answer == "i" ]] || [[ $answer == "I" ]]; then
echo "Changes ignored. Distrobox won't warn you before more changes are detected."
echo "To manually build the containers run \'distrobox-nixos-build\'."
echo $new_hash > $prev_hash_file
fi
fi
Expand All @@ -68,6 +64,41 @@ let

zshInitExtra = bashInitExtra;

fishInitExtra = ''
function distrobox-nixos-build
distrobox-assemble create --file ${containersFile}
end
set containers_file ${containersFile}
set prev_hash_file ${prevHashFile}
set new_hash (sha256sum $containers_file | cut -f 1 -d " ")
if test -f $prev_hash_file
set prev_hash (cat $prev_hash_file)
else
set prev_hash 0
end
if not test $new_hash = $prev_hash
read -p "Distrobox's containers list have changed. Do you want to build them now? [y/N/i]: " answer
if test $answer = "y" -o $answer = "Y"
distrobox-nixos-build
echo $new_hash > $prev_hash_file
else if test $answer = "i" -o $answer = "I"
echo "Changes ignored. Distrobox won't warn you before more changes are detected."
echo "To manually build the containers run 'distrobox-nixos-build'."
echo $new_hash > $prev_hash_file
end
end
set -e containers_file
set -e prev_hash_file
set -e new_hash
set -e prev_hash
set -e answer
'';

in {
meta.maintainers = [ lib.hm.maintainers.aguirre-matteo ];

Expand All @@ -82,6 +113,9 @@ in {
enableZshIntegration =
lib.hm.shell.mkZshIntegrationOption { inherit config; };

enableFishIntegration =
lib.hm.shell.mkFishIntegrationOption { inherit config; };

containers = mkOption {
type = with types; attrsOf (attrsOf (either bool str));
default = { };
Expand Down Expand Up @@ -117,5 +151,7 @@ in {

programs.bash.initExtra = mkIf cfg.enableBashIntegration bashInitExtra;
programs.zsh.initExtra = mkIf cfg.enableZshIntegration zshInitExtra;
programs.fish.interactiveShellInit =
mkIf cfg.enableFishIntegration fishInitExtra;
};
}

0 comments on commit a22407c

Please sign in to comment.