diff --git a/lib/shared/home-manager-packages.nix b/lib/shared/home-manager-packages.nix index daa54dc..d1f1640 100644 --- a/lib/shared/home-manager-packages.nix +++ b/lib/shared/home-manager-packages.nix @@ -15,6 +15,7 @@ let create-zellij-session = writeShellApplication ( import ./scripts/create-zellij-session.nix { inherit pkgs; } ); + deliver = writeShellApplication (import ./scripts/deliver.nix { inherit pkgs; }); export-video-list = writeShellApplication ( import ./scripts/export-video-list.nix { inherit pkgs username; } ); @@ -70,6 +71,7 @@ with pkgs; # Scripts. create-zellij-session + deliver notetaker run t diff --git a/lib/shared/scripts/deliver.nix b/lib/shared/scripts/deliver.nix new file mode 100644 index 0000000..d24999d --- /dev/null +++ b/lib/shared/scripts/deliver.nix @@ -0,0 +1,25 @@ +{ pkgs }: +{ + name = "deliver"; + + runtimeInputs = with pkgs; [ docker ]; + + text = '' + set +o pipefail + + # Based on https://github.com/jessarcher/dotfiles/blob/ef692c35d64db2c13674dfc850a23b6acf9e8f91/scripts/deliver. + + docker_compose_service_name=$(docker compose ps --services 2>/dev/null | grep '^app\|php$' | head -n1) + + if [[ "$docker_compose_service_name" != "" ]]; then + if [ -t 1 ]; then + "${pkgs.docker}/bin/docker" compose exec "$docker_compose_service_name" "$@" + else + # The command is not being run in a TTY + "${pkgs.docker}/bin/docker" compose exec -T "$docker_compose_service_name" "$@" + fi + else + "$@" + fi + ''; +}